XPath Tester

Your document and expression stay in this browser.

Paste XML or HTML with up to 1,000,000 characters. Evaluation happens in this browser with XPath 1.0.

Absolute or relative XPath 1.0. Prefixes declared in the document are registered automatically; a default namespace is available under the prefix d.

Writing XPath for scraping or XSLT is guess-and-check unless you have a live sandbox. This tester takes your XML or HTML in one pane and your expression in another, evaluates XPath 1.0 with your browser’s own engine, and lists every matched node with its kind, attributes, text content and serialised markup. Scalar expressions like count(//book) return their value directly, and namespace prefixes declared in the document are registered for you. Everything runs in your browser: the document is never uploaded.

How to test an XPath expression

  1. 1

    Paste XML or HTML

    Auto-detection switches to lenient HTML parsing when it sees an HTML doctype or root; you can also force XML or HTML mode.

  2. 2

    Enter your XPath

    Absolute (`/library/book`) or relative (`//div[@class='card']`), any XPath 1.0 expression.

  3. 3

    Evaluate

    Your browser's XPath engine runs the query locally; nothing is sent to a server.

  4. 4

    Inspect results

    Each match shows the node kind, attributes, trimmed text and serialised markup; up to 200 matches are listed.

XPath 1.0 essentials

Expression Matches
/books/book <book> children of root <books>
//book Every <book> anywhere in the document
//book[@id='42'] <book> with id attribute equal to 42
//book[1] First <book> of each parent (not doc)
(//book)[1] First <book> in the whole document
//book[title='1984'] <book> whose <title> text is “1984”
//book/@id id attributes of all <book> elements
//book[position() > 1] All <book> except the first
//book[last()] Last <book> per parent

Scalar expressions work too: count(//book) returns a number, string(//title) a string, and boolean(//book[@id]) true or false. The tester shows those values directly instead of a node list.

Common axes beyond child

  • ancestor::, all ancestors
  • following-sibling::, siblings after the current node
  • preceding-sibling::, siblings before
  • descendant::, all descendants
  • attribute:: (shortcut @), attributes of current node
  • parent:: (shortcut ..), parent element

HTML quirks

HTML is not strict XML, so the tester parses it leniently with your browser’s HTML parser instead of the strict XML one. HTML mode is auto-detected from <!DOCTYPE html> or an <html> root, and you can force either mode with the selector. In HTML mode tag and attribute names are lower-cased, so write your XPath in lowercase: //div[@class], not //DIV[@CLASS].

Namespaces

XML with namespaces needs prefix registration:

<rss xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <item>
    <content:encoded>...</content:encoded>
  </item>
</rss>

The tester scans the document for xmlns declarations and registers every prefix automatically, so //content:encoded just works. A default namespace (plain xmlns="...") has no prefix in the document, so the tester binds it to the prefix d: select <item> inside a default-namespace feed with //d:item. The registered bindings are listed next to the results.

What this tester does not evaluate

Browsers evaluate XPath 1.0, the same dialect used by most scraping stacks. Features from XPath 2.0 and later, such as matches(string, regex), tokenize(string, delimiter), for ... return expressions and sequence operators, are not part of it; you will find them in XSLT 2.0/3.0 toolchains. XPath 1.0 remains the most portable choice for web scraping.

Testing tips

  • Start broad, narrow down. //div first, then //div[@class], then the specific class value.
  • Check namespace declarations. Most “why does my XPath return nothing?” bugs are namespaces; look at the registered-prefixes list.
  • Mind case. XML is case-sensitive. HTML mode lower-cases names.
  • Test string() when extracting text. //p/text() vs string(//p) differ when there is nested markup.

Frequently Asked Questions

No, just XPath. Most browsers support both via document.querySelectorAll (CSS) and document.evaluate (XPath). Use whichever is clearer for the task.

HTML parsing lower-cases tag and attribute names. Make sure your XPath uses lowercase: //div[@class] not //DIV[@CLASS]. Also check the mode: forcing XML on sloppy HTML fails with a parse error, while HTML mode parses it leniently.

Prefixes declared in the document are registered automatically for your expression. A default namespace is bound to the prefix d, so //d:item selects <item> elements in a default-namespace document. The active bindings are listed with the results.

No. The document and the expression are evaluated by your browser’s own XPath engine and are not sent to our server, stored, or added to the page address; they only live in this browser session so the multi-step view can show your results.

Related Tools