Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM – The Node Tree

XML DOM Node Tree


The XML DOM views an XML document as a node tree.

All nodes in the tree have relationships with each other.


XML DOM Node Tree

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 the relationships between them. The tree starts at the root node and branches out to text nodes at the lowest level of the tree:

DOM node tree

The image above represents the XML file books.xml.


Parent, Child and Sibling Nodes

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

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

The image below shows part of a node tree and the relationships between the nodes:

Node tree

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

You will learn more about traversing the node tree in later chapters of this tutorial.


First Child - Last Child

Please look at 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, element is first child node of the element, and element is last child node of the element.

In addition, element is , , and parent node of the element.