DOM node type
XML DOM Node type
DOM is a document that represents a hierarchy of node objects.
Try it out - Example
The example below uses the XML file books.xml.
Function loadXMLDoc(), located in external JavaScript, is used to load XML files.
Display the nodeName and nodeType of all elements
Display the nodeName and nodeValue of all elements
Node type
The following table lists the different W3C node types, each node type may contain subclasses:
Node type | 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, which can retain a part of the document | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference Manual |
DocumentType | Provides an interface for entities defined in documents | 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 the element or attribute | None |
CDATASection | Represents the CDATA section in the document (the text will not be parsed by the parser) | None |
Comment | represents a comment | None |
Represents an entity | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference | |
Define a symbol declared in the DTD | None |
Node type | 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 |
Attribute name | Attribute value | |
Target | Content of node | |
#comment | Comment text | |
#text | Content of node | |
#cdata-section | Content of node | |
Entity name | null | |
Symbol Name | null |
Named constant | |
---|---|
ELEMENT_NODE | |
ATTRIBUTE_NODE | |
TEXT_NODE | |
CDATA_SECTION_NODE | |
ENTITY_REFERENCE_NODE | |
ENTITY_NODE | |
PROCESSING_INSTRUCTION_NODE | |
COMMENT_NODE | |
DOCUMENT_NODE | |
DOCUMENT_TYPE_NODE | ##11 |
12 | |