XML Input

XPath Results

e.g. //order[@status='paid'], //item/@sku, count(//item)

What this XPath tester does

Paste an XML document, type an XPath expression, and press Enter or Execute. Matching elements are shown as XML, attributes as @name="value", text nodes as text, and expressions such as count() or sum() return a single number, string or boolean. It is a quick way to check an XPath before you put it in XSLT, Selenium, a Java or Python parser, or a monitoring rule.

Queries run on the browser's built-in engine (document.evaluate), which implements XPath 1.0. XPath 2.0 and 3.1 additions such as matches(), if/then or sequences are not available and give an error. Namespace prefixes declared in your document work in queries, and a default namespace can be reached with the prefix default:. Everything runs in your browser; the XML is not uploaded.

Example queries to try

Click a query to run it against the sample orders (it loads the sample if the input is empty).

Titles of items in paid orders. The predicate in square brackets filters on an attribute.

Every sku attribute. Attribute results are shown as @sku="...".

How many items there are across all orders. Functions like count() and sum() return a single value.

Adds up the prices in one order. XPath 1.0 converts the text to numbers for you.

Text of items priced over 30. text() returns the text node instead of the element.

Customers whose order contains a given SKU, by testing a child's attribute inside the predicate.

Common Questions

What is XPath?

A small query language for picking nodes out of an XML document with path expressions such as /orders/order/customer, plus predicates in square brackets and a set of functions. It is used by XSLT, XML Schema, Selenium and most XML libraries.

Which XPath version is supported?

XPath 1.0. That is the version built into browsers, and the page hands your expression to it. Paths (/, //, ..), axes, attribute tests (@id), predicates and the 1.0 function library (count, contains, starts-with, sum, normalize-space and so on) work. XPath 2.0/3.1 functions raise an error.

How do I query a document with namespaces?

Use the prefixes the document declares, for example //soap:Body. For a default namespace (xmlns="..." with no prefix), XPath 1.0 needs a prefix, so use default:: //default:item. Alternatively match on the local name: //*[local-name()='item'].

Is my XML uploaded?

No. Queries run in your browser with its own XPath engine; your XML never leaves your computer.

Can I save my queries?

No. Keep the ones you reuse in your notes or code. The example queries above are a good starting point.

Does it work with large XML files?

Up to 5 MB. Bigger files are refused; on the command line, xmllint --xpath from libxml2 handles them.

Other XML Tools You Might Need

Querying is just one XML task. Here are other tools that work well together: