XDocument.NodeType 屬性

定義

取得此節點的節點類型。

C#
public override System.Xml.XmlNodeType NodeType { get; }

屬性值

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

範例

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

C#
// 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);

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

Document

備註

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

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

另請參閱