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.
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.
/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.
| Expression | Selects |
|---|---|
/bookstore/book | book children of the root element (absolute path) |
//title | Every title anywhere in the document |
//book/@category | The 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 | //price | Union 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 |
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'].
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.
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.
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.
No. Parsing and evaluation happen in your browser.