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

XPath Axes

XPath Axes


XML example document

We will use this XML document in the examples below:

<

bookstore

<

book

<

title

lang

=

"

en

"

Harry Potter

title

<

price

29.99

price

book

<

book

<

title

lang

=

"

en

"

Learning XML

title

<

price

39.95

price

book

bookstore

An axis defines a node-set relative to the current node.

Axis name Result
ancestor Selects all ancestors of the current node (parent, grandparent, etc.).
ancestor-or-self Selects all ancestors of the current node (parent, grandparent, etc.) and the current node itself.
attribute Selects all attributes of the current node.
child Selects all child elements of the current node.
descendant Selects all descendant elements of the current node (children, grandchildren, etc.).
descendant-or-self Selects all descendant elements of the current node (children, grandchildren, etc.) and the current node itself.
following Selects all nodes after the closing tag of the current node in the document.
following-sibling Selects all sibling nodes after the current node
namespace Selects all namespace nodes of the current node.
parent Selects the parent node of the current node.
preceding Selects all nodes before the opening tag of the current node in the document.
preceding-sibling Selects all sibling nodes before the current node.
self Selects the current node.