.NET API Documentation

XmlNodeType Enum

System.Xml

Specifies the type of the node in the XML document.

Members

  • None: No node is present.
  • Element: An element node.
  • Attribute: An attribute node.
  • Text: Text content.
  • CDATA: CDATA section content.
  • EntityReference: An entity reference.
  • Entity: An entity declaration.
  • ProcessingInstruction: A processing instruction.
  • Comment: A comment.
  • Document: The root of the document.
  • DocumentType: A document type declaration.
  • DocumentFragment: A document fragment.
  • Notation: A notation declaration.
  • XmlDeclaration: An XML declaration.
  • XmlSpace: An XmlSpace node.
  • EndElement: The end of an element.
  • EndEntity: The end of an entity.
  • XmlAttribute: An attribute node.
  • XmlSignificantWhitespace: Whitespace that is significant.
  • XmlWhitespace: Whitespace.
  • XmlSchema: An XML Schema definition.
  • XmlSchemaElement: An element in an XML Schema.
  • XmlSchemaAttribute: An attribute in an XML Schema.
  • XmlSchemaComplexType: A complex type in an XML Schema.
  • XmlSchemaSimpleType: A simple type in an XML Schema.

Remarks

The XmlNodeType enumeration is used by the NodeType property of the XmlReader and XmlNode classes to indicate the type of the current node. Knowing the node type allows you to determine how to process the node.

Example

The following example demonstrates how to read through an XML document and display the node type for each node.

using System;
using System.Xml;

public class Sample
{
    public static void Main()
    {
        // Create an XmlReader
        using (XmlReader reader = XmlReader.Create(@"
        Grid WorldKenton Varda200219.95"))
        {
            while (reader.Read())
            {
                // Display the node type and name if it is an element
                if (reader.NodeType == XmlNodeType.Element)
                {
                    Console.WriteLine("Element: {0}", reader.Name);

                    // Check for attributes
                    while (reader.MoveToNextAttribute())
                    {
                        Console.WriteLine("  Attribute: {0} = {1}", reader.Name, reader.Value);
                    }
                }
            }
        }
    }
}

See Also