XmlNodeKind Enum

Namespace: System.Xml

Enum Value Table

Member name Value Description
Element 0 The node is an element node.
Attribute 1 The node is an attribute node.
Text 2 The node is a text node.
CDATA 3 The node is a CDATA section.
EntityReference 4 The node is an entity reference node.
EntityDeclaration 5 The node is an entity declaration node.
ProcessingInstruction 6 The node is a processing instruction node.
Comment 7 The node is a comment node.
Document 8 The node is a document node.
DocumentType 9 The node is a document type node.
DocumentFragment 10 The node is a document fragment node.
Notation 11 The node is a notation node.
XmlDeclaration 12 The node is an XML declaration node.

Remarks

The XmlNodeKind enumeration is used to represent the different types of nodes that can exist in an XML document. This enumeration is part of the System.Xml namespace and provides a way to distinguish between elements, attributes, text, comments, and other XML constructs.

When working with the XmlNode class or other classes in the System.Xml namespace, understanding the XmlNodeKind helps in correctly processing and manipulating XML data. For example, you might check the XmlNodeKind of a node to determine whether it is an element that can contain child nodes or an attribute that holds a value.

Syntax

public enum XmlNodeKind

Members

The following table lists the members of the XmlNodeKind enumeration:

Example

The following C# code snippet demonstrates how to use XmlNodeKind to check the type of an XML node.

using System;
using System.Xml;

public class XmlNodeKindExample
{
    public static void Main(string[] args)
    {
        string xmlString = "<book category=\"fiction\"><title lang=\"en\">The Great Gatsby</title></book>";
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlString);

        XmlNode rootNode = doc.DocumentElement;
        if (rootNode != null)
        {
            Console.WriteLine($"Node Name: {rootNode.Name}, Node Kind: {rootNode.NodeType}");

            XmlAttributeCollection attributes = rootNode.Attributes;
            if (attributes != null)
            {
                foreach (XmlAttribute attr in attributes)
                {
                    Console.WriteLine($"Attribute Name: {attr.Name}, Node Kind: {attr.NodeType}");
                }
            }

            XmlNodeList children = rootNode.ChildNodes;
            foreach (XmlNode child in children)
            {
                Console.WriteLine($"Child Node Name: {child.Name}, Node Kind: {child.NodeType}");
            }
        }
    }
}