XPath Tester / Evaluator

Allows you to test your XPath expressions/queries against an XML file. This tool runs better than other existing XPath online tools as it supports most of the XPath functions (string(), number(), name(), string-length() etc.) and does not limit you to working against nodes.

The XPath tester fully supports XML namespaces, but the declarations MUST be explicit and MUST be on the root XML element. See the XPath Examples section for details.

You can choose to also include the XML item type (Attribute, Element, Text, etc.) as part of the output. This allows you to better understand which parts were matched.

XML Input

Option 1: Copy-paste your XML string here
Option 2: Or type in the URL to your XML file

XPath expression

Include the XML item type in output:

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">
		<actor id="1">Christian Bale</actor>
		<actor id="2">Liam Neeson</actor>
		<actor id="3">Michael Caine</actor>
		<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>

1. Select the document node


2. Select the 'root' element


3. Select all 'actor' elements that are direct children of the 'actors' element.


4. Select all 'singer' elements regardless of their positions in the document.


5. Select the 'id' attributes of the 'singer' elements regardless of their positions in the document.


6. Select the textual value of first 'actor' element.


7. Select the last 'actor' element.


8. Select the first and second 'actor' elements using their position.

//actor[position() < 3]

9. Select all 'actor' elements that have an 'id' attribute.


10. Select the 'actor' element with the 'id' attribute value of '3'.


11. Select all 'actor' nodes with the 'id' attribute value lower or equal to '3'.


12. Select all the children of the 'singers' node.


13. Select all the elements in the document.


14. Select all the 'actor' elements AND the 'singer' elements.


15. Select the name of the first element in the document.


16. Select the numeric value of the 'id' attribute of the first 'actor' element.


17. Select the string representation value of the 'id' attribute of the first 'actor' element.


18. Select the length of the first 'actor' element's textual value.


19. Select the local name of the first 'singer' element, i.e. without the namespace.


20. Select the number of 'singer' elements.


21. Select the sum of the 'id' attributes of the 'singer' elements.