XPath Tester

Type an XPath expression, paste XML, and see every node it selects. Uses your browser's built-in XPath 1.0 engine; nothing is uploaded.

How to test an XPath expression

  1. Paste your XML into the left box (a bookstore sample is loaded to start with).
  2. Type an expression, or click one of the examples, and press Enter or Evaluate.
  3. Each match is listed with its type (element, attribute, text) and its absolute path, such as /bookstore/book[3]/title, so you can see exactly which node was selected. Functions such as count() or sum() return a single number, string or boolean.

The expression is evaluated by the browser's own document.evaluate, the same XPath 1.0 engine that Selenium, Playwright and Puppeteer use when they locate elements by XPath, so an expression that works here works there.

XPath syntax cheat sheet

ExpressionSelects
/bookstore/bookbook children of the root element (absolute path)
//titleEvery title anywhere in the document
//book/@categoryThe category attribute of every book
//book[1] / //book[last()]First / last book (positions start at 1, not 0)
//book[@category='web']Books whose attribute equals a value
//book[price > 35]Books with a child element compared as a number
//title/text()The text nodes inside titles
//book[contains(title, 'XML')]Partial text match (case-sensitive)
//book[starts-with(@category, 'c')]Attribute prefix match
//author/..Parent of each author
//title | //priceUnion of two node sets
count(//book), sum(//price)Number results
//book[not(@category)]Books without the attribute
//book/following-sibling::book[1]Axes: the next sibling book

XML namespaces

A common surprise: //item returns nothing for an RSS, SOAP, SVG or Maven file. If the document declares a default namespace (xmlns="..."), XPath 1.0 only matches elements in that namespace through a prefix. This tester binds every prefix declared in your document automatically and maps the default namespace to d, so write //d:item or /d:project/d:version. Prefixed names such as //soap:Body work as they appear in the document. As an alternative that ignores namespaces, use //*[local-name()='item'].

XPath 1.0 vs 2.0 and 3.1

Browsers implement XPath 1.0. Functions added later, such as matches(), lower-case(), string-join() or if ... then ... else, report an error here. For a case-insensitive match in 1.0, use translate(): //title[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'xml')]. Working with JSON instead of XML? The equivalent query language is JSONPath; try the JSONPath tester or the jq playground.

FAQ

Can I test XPath against an HTML page?

Yes, if the HTML is well-formed (XHTML). For browser HTML, open DevTools and run $x("//a/@href") in the console, which uses the same engine.

Why does my expression return nothing?

The usual causes are a default namespace (use d: as described above), a case mismatch (XPath is case-sensitive) or positions counted from 0 instead of 1.

Is my XML uploaded?

No. Parsing and evaluation happen in your browser.