XCData.NodeType 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此节点的节点类型。
public:
 virtual property System::Xml::XmlNodeType NodeType { System::Xml::XmlNodeType get(); };public override System.Xml.XmlNodeType NodeType { get; }member this.NodeType : System.Xml.XmlNodeTypePublic Overrides ReadOnly Property NodeType As XmlNodeType属性值
示例
以下示例创建一个 XML 树,其中包含各种类型的节点。 然后循环访问树,并打印每个节点的节点类型。
// Note that XNode uses XmlNodeType, which is in the System.Xml namespace.  
XDocument xmlTree = new XDocument(  
    new XComment("a comment"),  
    new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"hello.xsl\""),  
    new XElement("Root",  
        new XAttribute("Att", "attContent"),  
        new XElement("Child1",  
            new XCData("CDATA content")  
        ),  
        new XElement("Child2",  
            new XText("Text content")  
        )  
    )  
);  
foreach (XNode node in xmlTree.DescendantNodes())  
{  
    Console.WriteLine(node.NodeType);  
    if (node.NodeType == XmlNodeType.Element)  
    {  
        foreach (XAttribute att in ((XElement)node).Attributes())  
            Console.WriteLine(att.NodeType);  
    }  
}  
Dim xmlTree As XDocument = _   
    <?xml version="1.0" encoding="utf-8"?>  
        <!--a comment-->  
        <?xml-stylesheet type='text/xsl' href='hello.xsl'?>  
        <Root Att="attContent">  
            <Child1><![CDATA[CDATA content]
注解
由于派生自 XObject 包含 NodeType 属性的所有类,因此可以编写对特定子类集合进行操作的代码 XObject。 然后,代码可以测试集合中每个节点的节点类型。