Javatpoint Logo
Javatpoint Logo

XPath Nodes

There are seven kinds of nodes in XPath:

  1. Element
  2. Attribute
  3. Text
  4. Namespace
  5. Processing-instruction
  6. Comment
  7. Document nodes.

An XML document can be specified as a tree of nodes. The topmost element of the tree is called the root element.

Xpath Nodes 1

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

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:

Chetan Bhagat

"en"


Relationship of Nodes

Parent Node

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.

Children Nodes

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.

Siblings Nodes

The nodes having the same parent are known as siblings. In this example, the title, author, year, and price elements are all siblings.

Ancestors

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.

Descendants

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.

Next TopicXPath Syntax




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA