XDocument.NodeType 屬性

定義

取得此節點的節點類型。

public:
 virtual property System::Xml::XmlNodeType NodeType { System::Xml::XmlNodeType get(); };
public override System.Xml.XmlNodeType NodeType { get; }
member this.NodeType : System.Xml.XmlNodeType
Public Overrides ReadOnly Property NodeType As XmlNodeType

屬性值

節點類型。 對於 XDocument 物件,此值為 Document

範例

下列範例顯示這個屬性的使用。

// Note that this property uses XmlNodeType, which is in the System.Xml namespace.
XDocument xmlTree = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XElement("Root", "content")
);
Console.WriteLine(xmlTree.NodeType);
' Note that this property uses XmlNodeType, which is in the System.Xml namespace.
Dim xmlTree As XDocument = _
    <?xml version='1.0' encoding='utf-8' standalone='yes'?>
        <Root>content</Root>
Console.WriteLine("{0}", xmlTree.NodeType)

這個範例會產生下列輸出:

Document

備註

因為衍生自 XObject 的所有類別都包含 NodeType 屬性,所以您可以撰寫程式碼,以操作物件集合,其中每個 類別的類型都是 的 XObject 子類別。 然後,您的程式碼可以測試集合中每個物件的節點類型。

適用於

另請參閱