XPath Tester

Evaluate an XPath expression against pasted XML or HTML using the browser's native document.evaluate, so results match what your own browser code sees.

You can also drop an XML or HTML file onto this box.

XPath examples — click one to try it
  • Direct children: every book right under the catalog
  • Anywhere below: every title, however deep
  • An attribute with a value: titles of the tech books
  • Compare a child’s value: titles of the pricier books
  • The last one: the title of the final book
  • Text only: the first book’s author, without the tags
  • Attributes: every id, wherever it is
  • A function in a condition: authors of books whose title mentions XPath
  • An axis: the author that follows each title
  • Count the matches instead of listing them
  • Add up the prices
  • By local name, whatever namespace the element is in
Pick a node from the document

Enter an XPath expression to see matching nodes.

See every node an XPath selects

XPath Tester lets you paste an XML or HTML document, type an XPath expression, and instantly see every node it selects. Each match is listed with a running count so you can confirm a query before wiring it into your scraper, XSLT stylesheet, or test suite.

How it works

Your document is parsed with the browser’s built-in DOMParser and queried with the native document.evaluate engine, so the results match what the same call returns in your own browser code. Everything runs locally — nothing is uploaded. The one request the tool makes is the one you ask for: with “Load from a web address”, your own browser fetches the http or https address you typed, so that host sees the request, and the document comes straight from there to you without passing through this site.

What the results show

An element match is shown as its outer HTML, an attribute match as the attribute value, and a text node as its text. Switch on “Parse as HTML” to query tag-soup HTML pages, or leave it off for strict, well-formed XML. In XML mode each match also says where it sits in the source — its line and column, or for a text node the element it is inside — and Format XML and Compress XML rewrite the document in place. A file can be dropped onto the box, and Copy link carries the document, the expression and the HTML switch, so the test can be sent on; a document too long for a link is left out and only the expression is kept.

Frequently asked questions

Why does it say the XML is not well-formed?

In strict XML mode the document must be well-formed — every tag closed and correctly nested. If you are querying an HTML page or a fragment, enable "Parse as HTML" so the parser tolerates unclosed or mismatched tags.

Which XPath features are supported?

The tool uses your browser’s native XPath engine, so element paths, wildcards, attribute selectors, predicates and text() selections all work just as they do in JavaScript. Namespace prefixes the document declares work as written — //media:thumbnail on a feed that declares media — while an element in a default namespace (xmlns with no prefix) has no prefix to name it in XPath 1.0, so it is reached with //*[local-name()='name'].

Can I build the expression without typing it?

Yes. Under “Pick a node from the document”, every element of the parsed document is listed, indented, with a button for it and for each of its attributes; a click puts that node’s absolute path in the expression box — /catalog/book[2]/title, with a position only where same-named siblings need one, and a local-name() step for an element in a default namespace. Above it, “XPath examples — click one to try it” lists worked expressions (children, attributes, predicates, last(), contains(), an axis, count() and sum()); a click puts one in the box, loading the Sample first if the box is empty.

Can I tidy the XML, drop a file in, keep the test in a link, or see where a match is?

Yes. Format XML and Compress XML rewrite the source box in place with the site’s XML formatter; they are there in XML mode only, since tag soup has void elements an XML indenter would nest the rest of the page under. A file dropped onto the box is read like Open file, and one that is not XML, HTML or text is refused. Copy link carries the document, the expression and the HTML switch, and opening that link brings the test back; a document too long for a link is left out and only the expression is kept. In XML mode each match carries its line and column in the source — for a text node, the element it is inside; in HTML mode no position is given, because the browser adds elements the text never had.

Can it also check the XML against a schema?

Not on this page. It checks only that the document parses — in XML mode a document that is not well-formed is refused with “This XML is not well-formed” — and then runs your expression over it. To validate against an XSD, a RELAX NG schema or a DTD, use the XSD Validator; to indent or compress XML on its own, the XML Formatter. Both are among the related tools on this page.