Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM – Node Types

XML DOM Node Types


The DOM is a document that represents a hierarchy of node objects.


Try it - Example

The following example uses the XML file books.xml.
function loadXMLDoc(), located in an external JavaScript, used to load the XML file.

Display the nodeName and nodeType of all elements

Display the nodeName and nodeValue of all elements


Node types

The table below lists the different W3C node types, each of which may contain subtypes:

Node types Description Subclass
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 can hold part of a document Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
DocumentType Provides an interface for entities defined in 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, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr Represents an attribute Text, EntityReference
Text Represents the text content of an element or attribute None
CDATASection Represents a CDATA section in the document (text that will not be parsed by the parser) None
Comment Represents a comment None
Entity Represents an entity Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Notation Defines a notation declared in the DTD None

Node Types - Return Values

The table below lists the node name (nodeName) and node value (nodeValue) returned by each node type (nodetype):

Node types Returned Node Name Returned Node Value
Document #document null
DocumentFragment #document fragment null
DocumentType Document type name null
Entity reference manual Entity reference name null
Element Element name null
Attr Attribute name Attribute values
ProcessingInstruction Goals The node's content
Comment #comment Comment text
Text #text The node's content
CDATASection #cdata-section The node's content
Entity Entity Name null
Notation Notation name null

Node Types - Named Constants

Node types Named Constants
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