XPath Tester — Online XPath Evaluator

🔒 Runs in your browser — nothing is sent to a server

XPath tester for live evaluation of any XPath 1.0 expression against an XML document. Paste your XML on the left, type an XPath query in the input above and the tester evaluates it on every keystroke using the browser's native `document.evaluate` — no server, no upload. Each match comes back with its node type (element, attribute, text, comment), its tag name or attribute name, the text content, and the full document path so you know exactly which node fired. Path expressions, predicates, attribute selection, axes (`parent::`, `following-sibling::`), and built-in functions (`count`, `contains`, `text()`) all work. Everything runs 100% inside your browser; the XML and the expression never leave your device, nothing is uploaded, logged or sent to any server.

Engine: browser-native document.evaluate — XPath 1.0.

Cheatsheet — XPath 1.0 syntax
  • /root — absolute path from root
  • //tag — tag at any depth
  • @attr — attribute
  • [1], [last()] — predicate by position
  • [@id='x'] — predicate by attribute
  • text() — text node child
  • node() — any node
  • parent::, .. — go up one level
  • following-sibling:: — next siblings
  • contains(., 'x') — string function
  • count(//book) — number function
  • name(), local-name() — element name

Why test XPath in the browser

XPath is small enough to learn in an afternoon and rich enough that even experienced practitioners benefit from a live tester. Predicates compose in subtle ways, axes have specific node-order semantics, and the function library has gotchas — `text()` selects only direct text-node children, `string(.)` returns the concatenated text of the entire subtree. A live XPath evaluator removes ambiguity: type the expression, see exactly which nodes come back, with their full path inside the document. This page does not call any server, so production XML — RSS feeds, SOAP envelopes, sitemap snapshots, scraped HTML, SVG fragments — can be pasted in without leaving your device. Use it to debug a stuck XML scraper, validate that an Ant or Maven `pom.xml` selector still works, or iterate on a Selenium locator before pasting it back into the test.

Reading the result list and the path column

Every match comes with four pieces of information. The *type* tells you whether you selected an element, attribute, text node or comment — useful when the expression accidentally lands on the wrong node kind. The *name* is the tag for elements, the attribute name (with `@` prefix) for attributes, or `text()` for text nodes. The *text content* is the concatenated string the browser would see when reading the node. The *path* is a position-aware locator — `/library/book[2]/title` — that tells you exactly which `book` produced the hit. When several nodes match, the path is the fastest way to confirm the expression returns them in the right order and from the right places, especially with axes like `following-sibling::` where the result order is structural rather than positional.

Examples

Input
//book/title
Output
Matches: <title>Invisible Cities</title>, <title>Ficciones</title>, <title>TAOCP</title>
XPath tester for child elements
Input
//book[@category='fiction']/title
Output
Matches: <title>Invisible Cities</title>, <title>Ficciones</title>
XPath query tester with attribute predicate
Input
//book[price<10]/author
Output
Match: <author>Borges</author>
Test XPath online — numeric predicate on child
Input
count(//book[contains(@category,"tech")])
Output
1
XPath expression builder — last() and string function

FAQ

How do I test an XPath expression online?

Paste your XML into the editor on the left, type an XPath expression in the input above and the XPath tester evaluates it live — there is nothing to submit. Every match is shown with its node type, name, text content and full path so you can spot exactly which element, attribute or text node was selected. The XML and the query never leave your browser.

Which version of XPath does the tester support?

XPath 1.0, served by the browser's built-in `document.evaluate` API. That covers the bulk of practical use cases: child and descendant axes, attribute selection (`@attr`), positional predicates (`[1]`, `[last()]`), expression predicates (`[@id='x']`, `[price<10]`), text and comment nodes, and the standard 1.0 function library (`count`, `contains`, `starts-with`, `string-length`, `name`, `local-name`, etc.).

How do I select an attribute with XPath?

Use `@` followed by the attribute name. `//book/@category` returns every `category` attribute on every `book`. To filter by attribute, put the test inside a predicate: `//book[@category='fiction']` selects books whose `category` is `fiction`. To return the attribute value as a string, wrap with `string(...)` or extract it explicitly.

What XPath axes are commonly useful?

The most-reached-for axes are `child::` (the default `tag`), `descendant::` (the default `//tag`), `attribute::` (or `@`), `parent::` (or `..`), `ancestor::`, `following-sibling::`, `preceding-sibling::`, and `self::` (or `.`). The XPath query tester supports them all because they are part of XPath 1.0. Axes are how you go sideways or upward in the tree, not just downward.

How are predicates different from filters in JSONPath?

XPath predicates `[…]` are general-purpose: they accept node-set tests (`[child]`), positional indices (`[1]`, `[last()]`), comparisons (`[@id='x']`, `[price<10]`) and function calls (`[contains(., 'foo')]`). They evaluate against the current node — the analogue of `@` in JSONPath. Multiple predicates chain: `//book[@category='fiction'][price<10]` keeps only books that pass both tests.

Why does my XPath return nothing?

Three common reasons: (1) namespace mismatch — XPath 1.0 in the browser does not bind a default namespace, so `//svg/circle` will fail when the document declares `xmlns="http://www.w3.org/2000/svg"`; use `local-name()` as a workaround. (2) case sensitivity — `Book` and `book` are different elements. (3) using `/` instead of `//` — `/book` requires `book` to be the root, while `//book` finds it anywhere.

Glossary

XPath

XPath is a query language for XML. It uses path-style syntax — `/root/child`, `//deep`, `@attr` — combined with predicates and functions to select nodes inside a document. XPath 1.0 (1999) is supported natively in every browser via `document.evaluate`; XPath 2.0 and 3.x add types, sequences and many functions, but require a separate engine. This XPath tester runs 1.0.

Node-set

XPath's primary data type is the node-set: an unordered collection of XML nodes returned by an expression. The XPath tester iterates the result of `document.evaluate` and shows every member as a row with its type, name and path. Other XPath types are string, number and boolean — produced by functions like `string()`, `count()`, `boolean()` — and these are shown in the result pane as a single value.

Predicate

A predicate is the part of an XPath step inside square brackets — `[…]` — that filters the current node-set. `[1]` keeps the first node, `[@id='x']` keeps nodes whose `id` attribute is `x`, `[price<10]` keeps nodes whose `price` child has a numeric value below 10. Multiple predicates chain. The XPath query tester evaluates them all in 1.0 semantics.

Axis

An axis defines the direction of traversal from the context node — `child::`, `descendant::`, `parent::`, `ancestor::`, `following-sibling::`, `preceding-sibling::`, `attribute::`, `self::`. Most expressions use the default `child::` (`tag`) or `descendant::` (`//tag`) and `attribute::` (`@attr`); the rest are useful for moving sideways and upward, where simpler languages would force a parent reference.

`document.evaluate`

`document.evaluate(expr, contextNode, nsResolver, resultType, result)` is the W3C DOM Level 3 XPath API exposed in every modern browser. It compiles an XPath 1.0 expression and returns an `XPathResult` whose `iterateNext()` yields each matched node. The XPath tester uses this directly — no third-party engine, no server hop — which keeps the bundle small and the privacy story straightforward.

Related tools