Category: Developer

XPath Tester

Run an XPath expression against XML and see what it matches.

Runs in your browserProcessed locally. Your input never leaves your device.

XPath 1.0, for example //book[@id='1']/title. Use // for any depth, @ for attributes, [] for predicates.

Include each match's text content, not just its path.

Details

About this tool

Evaluates an XPath 1.0 expression against your XML and lists every node it matches, with the path, type and value of each. Edit the expression and the result list updates, so you can build a selector by trying it rather than by guessing.

XPath is the query language for XML, and it is what sits underneath XSLT templates, XML schema constraints, SOAP and configuration tooling, most XML libraries in every language, and a good share of browser automation. The syntax is compact and unforgiving in equal measure, and the difference between an expression that returns everything and one that returns nothing is often a single slash.

The essentials are few. A single slash is a direct child, a double slash is a descendant at any depth, @ selects an attribute, and square brackets hold a predicate - a condition, or a position such as [1], which is one-based rather than zero-based and catches everyone once. Functions like contains(), starts-with() and text() cover most of the rest. Building an expression incrementally, checking the match count at each step, is far faster than writing the whole thing and wondering which part is wrong.

Namespaces are where most expressions quietly fail. In a document with a default namespace, //book does not match <book> - the element is in a namespace and the expression is not, so the parser considers them different names, even though they look identical on screen. The usual workarounds are a prefixed expression or local-name(), and knowing this is the difference between five minutes and an afternoon.

This is XPath 1.0, which is what the DOM implements and what almost every embedded XPath is written in. Everything runs in your browser, so the XML never leaves your device.

Keep going

  • Check whether XML is well-formed and pinpoint syntax errors.

    Runs in your browserDeveloper
  • Format C# with a CSharpier-compatible Roslyn engine running in the browser.

    Runs in your browserDeveloper

Good to know

Questions people actually ask

Which XPath version is supported?
XPath 1.0 - the version the DOM implements, and the one embedded in XSLT 1.0, XML Schema and most language libraries. XPath 2.0 and 3.1 add sequences, a real type system and many more functions, but require a separate processor and are far less common in the wild.
Does it work with namespaces?
It evaluates them correctly, which is exactly why //book returns nothing in a document with a default namespace: the element is namespaced and the expression is not, so despite looking identical they are different names. Use a prefixed expression, or match on local-name() when you do not care which namespace it is in.
Why does my expression match nothing?
Three causes cover nearly all of it: a namespace, as above; a leading slash when you meant a descendant search, since /book only matches a root element called book while //book finds one anywhere; and a predicate index, because XPath positions start at 1, not 0.
What is the difference between / and //?
A single slash is a direct child - /catalog/book matches book elements immediately inside catalog. A double slash is a descendant at any depth - //book matches every book in the document, however deeply nested. Using / where you meant // is the most common reason a correct-looking expression returns nothing.
Is my XML uploaded anywhere?
No. Both the document and the expression are evaluated in your browser, so an integration payload or an invoice with real data in it never leaves your device.