XPath Nodes
XPath terminology
Node
In XPath there are seven kinds of nodes: element, attribute, text, namespace, processing instruction, comment and document (root) node. An XML document is treated as a tree of nodes. The root of the tree is called the document node or root node.
Look at this XML document:
Examples of nodes in the XML document above:
lang="en" (attribute node)
Atomic values
An atomic value is a node with no parent and no children.
Examples of atomic values:
J K. Rowling
"en"
Items
An item is an atomic value or a node.
Node relationships
Parent
Every element and attribute has a parent.
In the example below, the book element is the parent of the title, author, year and price elements:
Children
An element node may have zero, one or more children.
In the example below, the title, author, year and price elements are all children of the book element:
Siblings
Nodes that have the same parent
In the example below, the title, author, year and price elements are all siblings:
Ancestors
A node's parent, its parent's parent, and so on.
In the example below, the ancestors of the title element are the book element and the bookstore element:
Descendants
A node's children, its children's children, and so on.
In the example below, the descendants of bookstore are the book, title, author, year and price elements: