Latest web development tutorials

XML DOM - node tree

XML DOM The XML document as a tree of nodes.

All the nodes in the tree have a relationship with each other.


XML DOM node tree

XML DOM XML document as a tree structure. This tree is called anode tree.

It can be accessed by all nodes in the tree. You can modify or delete their contents, you can create new elements.

Fengyun node tree shows a set of nodes and links between them. This tree starting from the root, and then branch out to the text nodes at the lowest level of the tree:

DOM node tree

The above picture represents the XML file the Books.xml .


Parent, child nodes and sibling nodes

Each node has a hierarchical relationship between the nodes in the tree.

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

  • In the node tree, called the root node at the top
  • Each root node than the node has a parent
  • Node can have any number of child nodes
  • The leaves are no node with children
  • Siblings is to have the same parent node node

Some pictures show a node tree below, and the relationship between the nodes:

Node tree

Because XML data is constructed in the form of a tree, so you can not know the exact structure of the tree and does not understand the type of case where the data contained in its traversal.

You will learn more about traversing the node tree of knowledge later in the tutorial section.


First child - the last child

Consider 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 XML above, <title> element is the first child of the <book> element and <price> element is the last child of the <book> element.

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