XPath Tester

Run XPath expressions against XML and list matching nodes.

The XPath Tester evaluates an XPath expression against an XML document and lists what it matches. Results show each node with its type and value, or a single number, string or boolean for expressions that return one. It is useful for building and debugging selectors for scrapers, XSLT, test automation and config processing.

What is XPath?

XPath is a query language for selecting parts of an XML document. An expression is a path through the tree, such as //book/title, with optional predicates in square brackets, such as //book[@id='2']. Paths can select elements, attributes (//book/@lang) and text nodes (//title/text()). XPath also has functions that return a plain value instead of nodes: count(//book) returns a number, string(//title) returns a string and boolean(//book) returns true or false. This tool uses the browser's built-in XPath engine, which implements XPath 1.0. That means newer XPath 2.0 and 3.x features such as sequences, regular expression functions and richer types are not available.

How to use XPath Tester

  1. Paste the XML Paste the document into the XML box. It must be well-formed and must not contain a DOCTYPE.
  2. Type an expression Enter your query in XPath expression, for example //book[year>1900]/title.
  3. Read the results For node results the heading shows how many nodes matched, and each row shows its number, type and value. For count(), string() or boolean() the heading shows the result type.
  4. Refine Edit the expression and the list updates immediately. A message of No matches. means the expression is valid but selected nothing.

Frequently asked questions

Which XPath version is supported?

XPath 1.0, as implemented by the browser's document.evaluate. XPath 2.0 and later functions, such as matches() or sequences, are not available.

Why does //ns:item return nothing or an error?

The prefix must be declared in the XML document itself, for example xmlns:ns="urn:x". The tool resolves prefixes using the document's own declarations, so a prefix that the document does not declare cannot be used.

Why does a default namespace make my query fail?

In XPath 1.0 an unprefixed name matches only elements with no namespace. If the document sets a default xmlns, its elements are in that namespace, and this tool can only match them through a prefix that the document declares. A common workaround is //*[local-name()='item'].

What is the difference between a node result and a scalar result?

Path expressions return a set of nodes, which are listed one per row. Functions such as count(), sum(), string() and boolean() return a single number, string or boolean.

Is my XML sent anywhere?

No. The document is parsed and queried in the page and is not sent to a server.