Basic XPath syntax
XPath Syntax
Article copied from W3Schools: https://www.w3schools.com/xpath/xpath_syntax.asp
The XML Example Document
We will use the following XML document in the examples below.
Selecting Nodes
In the table below we have listed some path expressions and the result of the expressions:
Predicates
Predicates are used to find a specific node or a node that contains a specific value.
Predicates are always embedded in square brackets.
Selecting Unknown Nodes
XPath wildcards can be used to select unknown XML elements.
Wildcard | Description |
---|---|
* | Matches any element node |
@* | Matches any attribute node |
node() | Matches any node of any kind |
In the table below we have listed some path expressions and the result of the expressions:
Path Expression | Result |
---|---|
/bookstore/* | Selects all the child nodes of the bookstore element |
//* | Selects all elements in the document |
//title[@*] | Selects all title elements which have any attribute |
Selecting Several Paths
By using the | operator in an XPath expression you can select several paths.
In the table below we have listed some path expressions and the result of the expressions: