XPath Tester
Paste or upload XML, run an XPath expression, and instantly see the matched nodes and values
XPath Examples
All of the following examples use this sample XML code. You can find more documentation on XPath expressions at W3Schools.com.
<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org"> <actors> <actor id="1">Christian Bale</actor> <actor id="2">Liam Neeson</actor> <actor id="3">Michael Caine</actor> </actors> <foo:singers> <foo:singer id="4">Tom Waits</foo:singer> <foo:singer id="5">B.B. King</foo:singer> <foo:singer id="6">Ray Charles</foo:singer> </foo:singers> </root>
- Select the document node
- Select the 'root' element
- Select all 'actor' elements that are direct children of the 'actors' element
- Select all 'singer' elements regardless of their positions in the document
- Select the 'id' attributes of the 'singer' elements regardless of their positions in the document
- Select the textual value of first 'actor' element
- Select the last 'actor' element
- Select the first and second 'actor' elements using their position
- Select all 'actor' elements that have an 'id' attribute
- Select the 'actor' element with the 'id' attribute value of '3'
- Select all 'actor' nodes with the 'id' attribute value lower or equal to '3'
- Select all the children of the 'singers' node
- Select all the elements in the document
- Select all the 'actor' elements AND the 'singer' elements
- Select the name of the first element in the document
- Select the numeric value of the 'id' attribute of the first 'actor' element
- Select the string representation value of the 'id' attribute of the first 'actor' element
- Select the length of the first 'actor' element's textual value
- Select the local name of the first 'singer' element, i.e. without the namespace
- Select the number of 'singer' elements
- Select the sum of the 'id' attributes of the 'singer' elements