XML DOM Node Types

DOM presents the document as a hierarchy of node objects.

Node Type

The following table lists different W3C node types and the child elements they can have:

Node Type Description Child Elements
Document Represents the entire document (the root node of the DOM tree).
  • Element (max. one)
  • ProcessingInstruction
  • Comment
  • DocumentType
DocumentFragment Represents a lightweight Document object that contains a portion of the document.
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
DocumentType Provides an interface to the entity defined for the document. None
ProcessingInstruction Represents a processing instruction. None
EntityReference Represents an entity reference element.
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
Element Represents an element (element element).
  • Text
  • Comment
  • ProcessingInstruction
  • CDATASection
  • EntityReference
Attr Represents an attribute.
  • Text
  • EntityReference
Text Represents text content within an element or attribute. None
CDATASection Represents a CDATA section in the document (text that is not parsed by the parser). None
Comment Represents a comment. None
Entity Represents an entity.
  • ProcessingInstruction
  • Comment
  • Text
  • CDATASection
  • EntityReference
Notation Represents a symbol declared in the DTD. None

Node Type - Return Values

The following table lists the values that the nodeName and nodeValue properties can return for each node type:

Node Type nodeName's Return Value nodeValue's Return Value
Document #document null
DocumentFragment #document fragment null
DocumentType Doctype Name null
EntityReference Entity Reference Name null
Element Element Name null
Attr Attribute Name Attribute Value
ProcessingInstruction target Node Content
Comment #comment Comment Text
Text #text Node Content
CDATASection #cdata-section Node Content
Entity Entity Name null
Notation Symbol Name null

NodeTypes - Named Constants

NodeType Named Constant
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE