XML DOM节点树
- Previous Page DOM Nodes
- Next Page DOM Parsing
The XML DOM views an XML DOM document as a node tree (node-tree).
All nodes in the tree have relationships with each other.
XML DOM节点树
The XML DOM views an XML document as a tree structure. This tree structure is calledNode tree.
All nodes can be accessed through this tree. Their content can be modified or deleted, and new elements can be created.
This node tree shows the collection of nodes and their relationships. The tree starts from the root node and then branches out to text nodes at the lowest level of the tree:

The above image represents an XML file books.xml.
Parent, child, and sibling nodes
Nodes in a node tree have a hierarchical relationship with each other.
Parent, child, and sibling nodes are used to describe this relationship. The parent node has child nodes, and child nodes at the same level are called sibling nodes (brothers or sisters).
- In a node tree, the top-level node becomes the root node
- Each node, except the root node, has a parent node
- A node can have any number of child nodes
- Leaves are nodes that do not have child nodes
- Sibling nodes are nodes that have the same parent node
The following image shows a part of the node tree and the relationships between nodes:

Because XML data is constructed in the form of a tree, it can be traversed without knowing the exact structure of the tree and without knowing the data types contained within it.
You will learn more about traversing the node tree in the later chapters of this tutorial.
Comment:Parent Node: Parent Node, Child Node: Children Node, Sibling Node: Sibling Node.
First Child Node - Last Child Node
Please see the following XML snippet:
<bookstore> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>
In the above XML, the <title> element is the first child element of the <book> element, and the <price> element is the last child element of the <book> element.
In addition, the <book> element is the parent element of the <title>, <author>, <year>, and <price> elements.
- Previous Page DOM Nodes
- Next Page DOM Parsing