Skip to content
ZeroServer.tools

XPath Tester

Validate XML grammar and evaluate XPath expressions against dynamic schemas with custom result highlights.

0 nodes matched
Valid Grammar
Query Presets
Query Results (0 matched)
No matching elements or attributes were found for the query.

Deep-dive: How XPath is evaluated

XPath (XML Path Language) is a declarative syntax for navigating XML trees. An XPath expression traverses the DOM to address parts of the markup, including elements, attributes, text nodes, and comments.

XML Grammar: Unlike HTML, XML is extremely rigid. Every element must have a corresponding closing tag, tags are case-sensitive, attribute values must be enclosed in quotes, and entities like < and & must be escaped. This tester validates grammar using the browser's native parser and raises error descriptions instantly.

Syntax Reference:

  • /bookstore/book: Selects children elements relative to root.
  • //price: Selects elements globally anywhere in the tree.
  • //@category: Selects attribute nodes.
  • //book[price > 10]: Uses predicates to filter elements by child node value constraints.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Checking an expression against real markup before putting it in a scraper or a transform.
  • Working out why a selector matches nothing when the element is clearly present.
  • Testing whether a predicate narrows a node set the way you intended.
  • Comparing an absolute path against a more robust relative one.
  • Confirming what a string or numeric expression evaluates to rather than a node set.

Frequently Asked Questions

What does an XPath expression select?
A node set from a document tree, addressed by path. `//book[@id='1']/title` finds any book element with that id anywhere in the document and returns its title child — the double slash being the descendant axis rather than a root path.
Why does my expression return nothing on an XML document?
Almost always namespaces. An element in a default namespace cannot be matched by its bare name — `//book` finds nothing if the document declares `xmlns`. You need a prefix bound in the evaluator, or `local-name()` as a workaround.
How do predicates and indexes work?
Predicates in square brackets filter, and a bare number is positional — `//item[1]` is the first matching item, one-indexed rather than zero. That off-by-one against every programming language is the most common XPath mistake.
What are the axes for?
Navigating in directions a path cannot express: `parent::`, `following-sibling::`, `ancestor::`, `preceding::`. They are what makes XPath more powerful than a CSS selector, which can only descend.
XPath or CSS selectors?
CSS for HTML in a browser — shorter and faster. XPath when you need to match on text content, walk upward to a parent, or address by position in a way CSS cannot express, which is why scraping and testing tools support both.

Common errors and gotchas

  • Ignoring namespaces. A default namespace in the document makes an unprefixed expression match nothing at all.
  • Assuming positions are zero-based. XPath indexes from one, which is the most common off-by-one here.
  • Writing an absolute path against markup that a parser has normalised, for example by inserting a tbody.
  • Confusing `//a[1]` with `(//a)[1]`, which select very different things.
  • Expecting a text node and getting an element, then reading the empty result as no match.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate