The DOMDocument object can be described as a tree (see Page 2 of our last column for an example). The entities of the tree are called nodes. There are twelve node types in DOMDocument. The following table lists them. For each node, you can also find in this table which node types can be its parent, and which types can be its children.
| Value | 1 |
| Description | An element |
nodeTypeString | "element" |
| Can have child nodes of type: | Element, Text, Comment, ProcessingInstruction, CDATASection, and EntityReference |
| Can be a child node of type: | Document, DocumentFragment, EntityReference, and Element |
| Value | 2 |
| Description | An attribute |
nodeTypeString | "attribute" |
| Can have child nodes of type: | Text and EntityReference |
| Can be a child node of type: | none |
| Value | 3 |
| Description | The text content of a tag |
nodeTypeString | "text" |
| Can have child nodes of type: | none |
| Can be a child node of type: | Attribute, DocumentFragment, Element, and EntityReference |
| Value | 4 |
| Description | A CDATA section. The XML parser should consider the section as text only. |
nodeTypeString | "cdatasection" |
| Can have child nodes of type: | none |
| Can be a child node of type: | DocumentFragment, EntityReference, and Element |
| Value | 5 |
| Description | An entity reference |
nodeTypeString | "entityreference" |
| Can have child nodes of type: | Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReference |
| Can be a child node of type: | Attribute, DocumentFragment, Element, and EntityReference |
| Value | 6 |
| Description | An expanded entity |
nodeTypeString | "entity" |
| Can have child nodes of type: | Any node included in an expanded entity. For example: Text and EntityReference |
| Can be a child node of type: | DocumentType |
| Value | 7 |
| Description | A processing instruction |
nodeTypeString | "processinginstruction" |
| Can have child nodes of type: | none |
| Can be a child node of type: | Document, DocumentFragment, Element, and EntityReferenceDocumentType |
| Value | 8 |
| Description | A comment |
nodeTypeString | "comment" |
| Can have child nodes of type: | none |
| Can be a child node of type: | Document, DocumentFragment, Element, and EntityReference |
| Value | 9 |
| Description | A document object. As the root of the document tree, provides access to the entire XML document. It is created using the progID "Microsoft.XMLDOM" or through a data island using <XML> or <SCRIPT LANGUAGE=XML>. |
nodeTypeString | "document" |
| Can have child nodes of type: | Element (maximum of one), ProcessingInstruction, Comment, and DocumentType |
| Can be a child node of type: | none |
| Value | 10 |
| Description | The document type, as indicated by the <!DOCTYPE>. |
nodeTypeString | "documenttype" |
| Can have child nodes of type: | Notation and Entity |
| Can be a child node of type: | Document |
| Value | 11 |
| Description | A document fragment |
nodeTypeString | "documentfragment" |
| Can have child nodes of type: | Notation and Entity |
| Can be a child node of type: | Document |
| Value | 12 |
| Description | A document type's notation |
nodeTypeString | "notation" |
| Can have child nodes of type: | any |
| Can be a child node of type: | DocumentType |
There are twelve node types in the DOMDocument tree. The nodeName property of these nodes depends on the node type. In some node types, the nodeName property reflects a user-given name. For example, the nodeName property of the attribute node is the name of the property, as assigned by the author. In other node types, the nodeName property contains a fixed string. For example, the nodeName property of the text node contains the string "#text". The following table lists the nodeName property of all node types:
| Value | nodeTypeString | nodeName |
1 | "element" | Contains the name of the XML tag, with any namespace prefix included if present. |
2 | "attribute" | Contains the name of the attribute. |
3 | "text" | Contains the literal string "#text". |
4 | "cdatasection" | Contains the literal string "#cdata-section". |
5 | "entityreference" | Contains the name of the entity referenced. Note that the name does not include the leading ampersand or the trailing semicolon. The name includes the namespace if one is present. |
6 | "entity" | Contains the name of the entity. |
7 | "processinginstruction" | Contains the target; the first token following the <? characters. |
8 | "comment" | Contains the literal string "#comment". |
9 | "document" | Contains the literal string "#document". |
10 | "documenttype" | Contains the name of the document type; for example, xxx in <!DOCTYPE xxx ...>. |
11 | "documentfragment" | Contains the literal string "#document-fragment". |
12 | "notation" | Contains the name of the notation. |