XML DOM Node Type
The DOM is a document that represents a hierarchy of node objects.
Try it Yourself - Examples
The following examples use an XML filebooks.xml。
FunctionloadXMLDoc(), located in external JavaScript, 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, and 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 that can retain a portion of the document | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference Manual |
| 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 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 type - return value
The following table lists the node name (nodeName) and node value (nodeValue) returned by each node type (nodetype):
| Node Type | The returned node name | The 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 | Property 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 |
Node type - 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 |
other extensions