What is XPath (XML Path Language)?
XPath (XML Path Language) is a query language for selecting nodes from an XML document. In addition, you may use XPath to compute values such as strings, numbers, or Boolean values from the content of an XML document.
As a matter of fact XPath language is based on a tree representation of the XML document. It provides the ability to navigate around the tree, thereby selecting nodes by a variety of criteria. The most important kind of expression in XPath is a location path. A location path consists of a sequence of location steps. Further, each location step has three components an axis, a node test, and zero or more predicates.
XPath expression is evaluated with respect to a context node.
- Axis Specifier such as ‘child’ or ‘descendant’ specifies the direction to navigate from the context node.
- Node test and the predicate are used to filter the nodes specified by the axis specifier.
Types of XPath (XML Path Language) Syntax
The XPath syntax comes in two ways –
- Abbreviated syntax, is more compact and allows XPaths to be written and read easily using intuitive and, in many cases, familiar characters and constructs.
- Full syntax is more verbose, but allows for more options to be specified, and is more descriptive if read carefully. Also referred as expanded syntax.