XPath Nodes

XPath Terminology:

Nodes:

The element, attribute, text, namespace, processing-instruction, comment, and document nodes are the seven kinds of nodes in XPath. The trees of nodes are the XML documents, and the root element is the topmost element of the tree.

Example:




  
    ABC
    Author Name
    2020
    100
  

Explanation:

The nodes in the above XML document are:

Root element node : <bookstore>

Element node: <author>Author Name</author>

Attribute node: lang=”en”

Atomic values:

The nodes with no children or parent are called the Atomic values.

Example:

The atomic values in the above XML document are:

Author Name

“en”

Items:

The atomic values or nodes are called the items.

Relationship of Nodes:

Parent:

In XPath, one parent is there for each element and attribute.

Example:

In the above XML document, the book element is the parent of the title, author, year, and price.

Children:

There may be zero, one or more children for each element node.

Example:

In the above XML document, the title, author, year, and price elements are the children of the book element.

Siblings:

Nodes with the same parent are called siblings.

Example:

In the above XML document, the title, author, year, and price elements are all siblings.

Ancestors:

The ancestors are the node’s parent, parent’s parent, etc.

Example:

In the above XML document, the ancestors of the title element are the book element and the bookstore element.

Descendants:

The descendants are the node’s children, children’s children, etc.

Example:

In the above XML document, the descendants of the bookstore element are the book, title, author, year, and price elements.