XML DOM tutoria...login
XML DOM tutorial
author:php.cn  update time:2022-04-13 15:27:56

DOM node tree


XML DOM Node tree


XML DOM treats an XML document as a node tree.

All nodes in the tree have relationships with each other.


XML DOM node tree

XML DOM treats the XML document as a tree structure. This tree structure is called node tree.

All nodes can be accessed through this tree. Their contents can be modified or deleted, and new elements can be created.

This node tree shows a collection of nodes and the connections between them. The tree starts at the root node and branches out to text nodes at the lowest level of the tree:

nodetree.gif

The image above represents the XML file books.xml.


Parent nodes, child nodes and sibling nodes

Nodes in the node tree have hierarchical relationships with each other.

Parent nodes, child nodes and sibling nodes are used to describe this relationship. A parent node has child nodes, and child nodes located at the same level are called sibling nodes (brothers or sisters).

  • In the node tree, the top node is called the root node

  • Every node other than the root node has a parent node

  • Nodes can have any number of child nodes

  • A leaf is a node that has no child nodes

  • Sibling nodes are nodes that have the same parent node

The following picture shows a part of the node tree and the relationship between nodes:

navigate.gif

Because XML data is structured in the form of a tree, it can be traversed without knowing the exact structure of the tree and the types of data it contains.

You will learn more about traversing node trees later in this tutorial.


First child node - last child node

Please see the following XML fragment:

<bookstore>
​ <book category="cooking">
​​ <title lang="en">Everyday Italian</title>
​​ <author>Giada De Laurentiis</author>
​​ <year>2005</year>
​​ <price>30.00</price>
​ </book>
</bookstore>

In the above XML, the <title> element is the first child node of the <book> element, and the <price> element is the last child node of the <book> element.

In addition, the <book> element is the parent node of the <title>, <author>, <year>, and <price> elements.


php.cn