Share via


Types of XML Nodes

When an XML document is read into memory as a tree of nodes, the node types for the nodes are decided when the nodes are created. The XML Document Object Model (DOM) has several kinds of node types, determined by the World Wide Web Consortium (W3C) and listed in section 1.1.1 The DOM Structure Model. The following table lists the node types, the object assigned to that node type, and a short description of each.

DOM node type

Object

Description

Document

XmlDocument Class

The container of all the nodes in the tree. It is also known as the document root, which is not always the same as the root element.

DocumentFragment

XmlDocumentFragment Class

A temporary bag containing one or more nodes without any tree structure.

DocumentType

XmlDocumentType Class

Represents the <!DOCTYPE…> node.

EntityReference

XmlEntityReference Class

Represents the non-expanded entity reference text.

Element

XmlElement Class

Represents an element node.

Attr

XmlAttribute Class

Is an attribute of an element.

ProcessingInstruction

XmlProcessingInstruction Class

Is a processing instruction node.

Comment

XmlComment Class

A comment node.

Text

XmlText Class

Text belonging to an element or attribute.

CDATASection

XmlCDataSection Class

Represents CDATA.

Entity

XmlEntity Class

Represents the <!ENTITY…> declarations in an XML document, either from an internal document type definition (DTD) subset or from external DTDs and parameter entities.

Notation

XmlNotation Class

Represents a notation declared in the DTD.

Even though an attribute (attr) is listed in the W3C DOM Level 1 section 1.2 Fundamental Interfaces as a node, it is not considered a child of any element node.

The following table shows additional node types not defined by the W3C, however they are available for use in the Microsoft .NET Framework object model as XmlNodeType enumerations. Therefore, there is no matching DOM node type column for these node types.

Node type

Description

XmlDeclaration

Represents the declaration node <?xml version="1.0"…>.

XmlSignificantWhitespace

Represents significant white space, which is white space in mixed content.

XmlWhitespace

Represents the white space in the content of an element.

EndElement

Returned when XmlReader gets to the end of an element.

Example XML: </item>

For more information, see XmlNodeType Enumeration.

EndEntity

Returned when XmlReader gets to the end of the entity replacement as a result of a call to ResolveEntity. For more information, see XmlNodeType Enumeration.

To view a code example that reads in XML and uses a case construct on the node types to print information about the node and its contents, see XmlSignificantWhitespace.NodeType Property.

For more information on the object hierarchy of the node types and their equivalent object name, see XML Document Object Model (DOM) Hierarchy. For more information on the objects created in the node tree, see Mapping the Object Hierarchy to XML Data.

See Also

Concepts

XML Document Object Model (DOM)