There are seven kinds of nodes in XPath:
- Document nodes.
An XML document can be specified as a tree of nodes. The topmost element of the tree is called the root element.
Let’s take an example of XML document to understand the different terminology of XPath nodes.
An XML document:
Nodes in the above XML document:
Atomic values are used to specify the nodes with no children or parent. For example: In the above XML document, following are the atomic values:
Relationship of Nodes
Each element and attribute has a parent which is a top element of the respective element or attribute.
See this example:
In this example, the book element is the parent of the title, author, year, and price.
The children nodes can have zero, one or more children. In this example, the title, author, year, and price elements are all children of the book element.
The nodes having the same parent are known as siblings. In this example, the title, author, year, and price elements are all siblings.
A node’s parent or parent’s parent is specified as ancestor. In this example, the ancestors of the title element are the book element and the library element.
A descendent is specified as a node’s children or children’s children. In this example, descendants of the library element are the book, title, author, year, and price elements.