XML DOM Node Types (Node Types)

Example

In the following example, we will use the XML file books.xmlas well as the JavaScript function loadXMLDoc().

Displays the node names and node types of all elements
Displays the node names and node values of all elements

Node type

The following table lists different W3C node types and their possible child elements:

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 part 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 the text content within an element or attribute. None
CDATASection Represents a CDATA section in the document (the text 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 DTD. None

Node type - The returned value

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

Node type The return value of nodeName The return value of nodeValue
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 The content of the node
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