XML DOM Node Types
DOM represents a document with a node object hierarchy.
Try It Yourself - Examples
The following examples use the XML file books.xml. loadXMLDoc(), located in an external JavaScript, is used to load the XML file.
Display nodeName and nodeType of all elements
Display nodeName and nodeValue of all elements
Node Types
The table below lists different W3C node types, each potentially containing subclasses:
Node Type | Description | Subclasses |
---|---|---|
Document | Represents the entire document (root of the DOM tree) | Element (max. one), ProcessingInstruction, Comment, DocumentType |
DocumentFragment | Represents a "lightweight" Document object that can hold a portion of a document | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
DocumentType | Provides an interface to the 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 not parsed by the parser) | None |
Comment | Represents a comment | None |
Entity | Represents an entity | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
Notation | Defines a symbol declared in the DTD | None |
Node Types - Return Values
The table below lists the node name (nodeName) and node value (nodeValue) returned for each node type:
Node Type | Returned Node Name | Returned Node Value |
---|---|---|
Document | #document | null |
DocumentFragment | #document-fragment | null |
DocumentType | Document type 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 | Notation name | null |
Node Types - Named Constants
Node Type | 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 |