CodeKitHub
Code Tools

XPath Tester

Last updated:

XPath is a query language for selecting nodes from an XML (or HTML) document using path expressions, similar to how a file path selects a file in a folder tree. This tool lets you paste any XML, write an XPath expression, and instantly see which nodes match — including node counts, serialized output and clear error messages for bad XML or bad XPath syntax. It runs entirely in your browser using the native `document.evaluate` engine built into every modern browser, so nothing you paste is ever uploaded anywhere.

What Is This Tool?

XPath (XML Path Language) is a W3C standard for navigating and selecting nodes — elements, attributes, text — inside an XML document using compact path-like syntax, e.g. `//book[price>30]/title` selects every `<title>` whose sibling `<price>` is greater than 30, anywhere in the document. It's used by XSLT stylesheets, XML validation tools, web scrapers, browser automation frameworks (Selenium, Playwright) and many programming languages' XML libraries.

The current version implemented by every major browser — Chrome, Firefox, Safari, Edge — is XPath 1.0, the original 1999 W3C Recommendation. This tool uses that exact native engine via the browser's `document.evaluate()` API, so results here match what you'd get from browser DevTools or any JavaScript running in a browser. It does not implement the later XPath 2.0/3.0/3.1 specifications (those add functions like `for`, sequences, and regex matching) — see the FAQ for what that means in practice.

An expression can return one of two kinds of result: a node-set (zero or more matching elements, attributes or text nodes, which this tool serializes and lists one per line with a count), or a scalar value — a number, string or boolean — when the expression itself computes a value, like `count(//book)` or `//book[1]/title = 'Dune'`.

Why Use It?

  • Debug an XPath expression before hard-coding it into a web scraper, Selenium/Playwright test, or XSLT stylesheet.
  • Quickly check whether a given XPath selects the node you expect from a real XML/HTML sample.
  • See exact match counts and serialized output instead of guessing from code.
  • Get immediate, readable errors for malformed XML or invalid XPath syntax instead of a cryptic stack trace.
  • 100% client-side: your XML and expression never leave your browser.

How to Use

  1. Paste or edit your XML (or HTML) in the input box — a sample bookstore document is pre-filled so you can see it working immediately.
  2. Type an XPath expression in the expression field, or edit the pre-filled example.
  3. Click "Evaluate" (or press Enter in the expression field).
  4. Read the matched nodes below, with a count at the top; scalar results (numbers, strings, booleans) are shown directly.
  5. If the XML or the expression is invalid, a specific error message replaces the results.

Example

Input

XML:
<bookstore>
  <book><title>The Great Gatsby</title><price>12.99</price></book>
  <book><title>Learning XPath</title><price>34.50</price></book>
  <book><title>Dune</title><price>45.00</price></book>
</bookstore>

XPath: //book[price>30]/title

Output

✓ 2 node(s) matched
<title>Learning XPath</title>
<title>Dune</title>

Only 2 of the 3 books have a price above 30, so exactly 2 <title> elements are returned — the third book (Gatsby, $12.99) is correctly excluded.

XPath vs CSS selectors at a glance

Both languages select nodes from a document, but they solve different problems. Use this table to pick the right tool for a given selection.

CapabilityXPathCSS selectors
Select by tag/class/id downwardYesYes — and usually faster
Select by visible/text contentYes — `contains(text(),'x')`No
Traverse upward to a parent/ancestorYes — `//div[span]/..`No (`:has()` is a newer partial exception)
Sibling-value comparisons (e.g. `price>30`)YesNo
Works outside a browser (server-side XML tooling, XSLT)YesNo — CSS selectors are browser/DOM specific

Related tools

Working with structured data formats? These tools pair well with XPath testing.

JSON Formatter · JWT Decoder

Frequently Asked Questions

What is XPath used for?

XPath selects nodes — elements, attributes, or text — out of an XML or HTML document using a path syntax. It's the selection language behind XSLT transformations, many XML validators, and it's widely used in web scraping and browser test automation (Selenium, Playwright, Cypress) to locate elements on a page, especially when CSS selectors alone can't express the condition needed.

XPath vs CSS selectors — which should I use?

They overlap but aren't equivalent. XPath can select a parent based on a child's content (`//div[span='Total']`), traverse upward to ancestors, and select by visible text (`//button[contains(text(),'Submit')]`) — CSS selectors cannot go upward in the tree and cannot match on text content at all. If you're just selecting by tag, class or ID going downward through the document, CSS selectors are simpler to write and generally faster to evaluate. Reach for XPath specifically when you need "select the parent of this text" or "select by what the element says," not just what it's tagged or classed.

Does this tool support XPath 2.0 or 3.0 functions?

No — and neither does any browser. Browsers implement XPath 1.0 (the 1999 W3C Recommendation) via `document.evaluate()`, and this tool uses that exact native engine, so it's accurate to what you'd get running the same expression in browser DevTools or JavaScript. Functions and features introduced in XPath 2.0/3.0/3.1 (like `for` expressions, sequences, or `matches()` with regex) are not available — only 1.0 functions such as `contains()`, `starts-with()`, `substring()`, `count()`, `position()` and `last()` work here.

What are some common XPath expressions I should know?

`//tag` selects every `<tag>` anywhere in the document. `//tag[@attr='value']` selects `<tag>` elements whose `attr` attribute equals `value`. `//tag[contains(text(),'x')]` selects `<tag>` elements whose direct text contains `x`. `//tag[1]` selects the first `<tag>` sibling in each parent. `//parent/child` selects `<child>` elements that are direct children of `<parent>`. `count(//tag)` returns a number instead of a node-set.

Does this tool handle XML namespaces?

Only the common no-namespace case is supported cleanly, which covers the vast majority of hand-written or scraped XML/HTML. If your document declares an XML namespace (e.g. `xmlns="..."` on the root element), `document.evaluate` requires a namespace-aware resolver function mapping prefixes to URIs, which this simple tool doesn't set up — expressions against namespaced XML may return zero matches even when they look correct. This is a known limitation, not a bug: strip the namespace declaration from your sample, or use the local-name() function (e.g. `//*[local-name()='title']`) as a workaround.

Is my XML or XPath expression sent to a server?

No. Everything runs locally using your browser's built-in `DOMParser` and `document.evaluate()` — the same engine your browser already uses internally. Nothing you type or paste ever leaves your device.

Related Tools