b2KIT

XPath Tester

Test XPath expressions against XML/HTML documents with node selection, result display, and expression builder.

Tested tool guide Tested browser tools Checked August 16, 2026

What XPath Tester does, with a checked example

Paste an XML or HTML document into one pane, type an XPath expression into the other, and the tool evaluates that expression against the pasted document, listing each node it matches along with the node's type and value. An expression builder assembles paths from common building blocks instead of requiring the full syntax from memory. The usual first surprise: the expression is evaluated against the document exactly as pasted, not against a live page, so anything a page's scripts inject after load will not match, and a valid expression can return nothing when tag case, implicit table structure, or namespaces do not line up.

Worked example

A concrete input and expected output from the current implementation.

Input

<library>
  <book id="1"><title>Pride and Prejudice</title><price>12.50</price></book>
  <book id="2"><title>Dune</title><price>9.99</price></book>
</library>

Expression: //book[price > 10]/title/text()

Expected output

One node matched: the text node "Pride and Prejudice", the title of the only book whose price is above 10.

The predicate [price > 10] converts each book's price text to a number and keeps the book only if that number exceeds 10, so 12.50 passes and 9.99 does not. The trailing /title/text() step then selects the text node under that book's title.

How the result is produced

1

Evaluation against a parsed tree

The document is parsed into a node tree and the expression is evaluated against it, entirely in the browser, so nothing is uploaded. A path is a chain of steps joined by slashes: an absolute path beginning with / starts at the document root, // selects descendants at any depth, and a predicate in square brackets filters the nodes of the step it follows. The result is a node-set or a scalar value.

2

Expression builder and result types

Every XPath expression returns one of four types: a node-set, a string, a number, or a boolean. Node-set results are listed with one entry per matched node; the other types appear as a single scalar value. The expression builder puts a path together from pieces: element names, attribute tests such as @href, predicates such as [@class='x'] or [3], and functions such as contains(), count(), and position() combine into a step-by-step path.

Good uses

  • Confirming a selector before writing scraper or automation code: paste the page HTML, verify the XPath picks the intended elements, then port it to your script.
  • Checking a path against XML you generate or receive, such as sitemap.xml, an RSS feed, or a config file, before relying on it in an XSLT transform or a validation routine.
  • Settling predicate questions, for example what //item[position() <= 3] returns versus //item[3], or why [last()] does not pick the node you expected, without building a test harness.

Limits and checks

  • Version of XPath: browsers natively evaluate XPath 1.0, which has no lower-case(), matches(), or ends-with() and no || operator. If the evaluator is 1.0, expressions using 2.0+ functions fail or return nothing, and results may differ from a 3.1 processor.
  • Pasted HTML is parsed as HTML, not XML: tag names are lowercased, so //DIV matches nothing while //div matches, and tables gain an implicit tbody, so //table/tr returns nothing where //table//tr works.
  • An unprefixed name in XPath means the no-namespace namespace. XML that declares a default namespace (xmlns="...") makes a path like //title silently return nothing until you bind a prefix to that URI and write //x:title.

Common questions

Why does my expression match in the browser's developer tools but not in the tester?

Developer tools run against the live DOM, which includes elements added or moved by JavaScript; the tester evaluates the document exactly as you pasted it. Paste the page's current markup, for instance by copying outerHTML of the relevant element in the inspector, and the results should agree. Content that only exists after scripts run matches only if you paste a rendered copy.

Can I test an expression against JSON data?

No. XPath addresses nodes in an XML or HTML tree, not JSON objects. JSON is queried with a different language, such as JSONPath, or with an XPath 3.1 processor that maps JSON into XML first. If this tool's evaluator implements XPath 1.0, it cannot process JSON at all, so convert the data to XML before pasting.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools