Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
NodeType Property
Collapse the table of content
Expand the table of content

XDocument.NodeType Property

Gets the node type for this node.

Namespace:  System.Xml.Linq
Assemblies:   System.Xml.XDocument (in System.Xml.XDocument.dll)
  System.Xml.Linq (in System.Xml.Linq.dll)

'Declaration
Public Overrides ReadOnly Property NodeType As XmlNodeType

Property Value

Type: System.Xml.XmlNodeType
The node type. For XDocument objects, this value is Document.

Because all classes that derive from XObject contain a NodeType property, you can write code that operates on collections of objects where the type of each is a subclass of XObject. Your code can then test for the node type of each object in the collection.

The following example shows the use of this property.

' 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)

This example produces the following output:

Document

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft