XPath Tester
Test and evaluate XPath expressions against XML or HTML instantly in your browser. Powered by
the native document.evaluate() API — 100% client-side.
Enter an XPath expression and XML input to see matches here.
Sample Expressions (click to try)
About the XPath Tester
The XPath Tester lets you write and evaluate XPath expressions against any XML or HTML document in real time. Paste your markup, type an expression, and see matched nodes instantly — no page reload, no server round-trip.
This tool is powered by the browser's native document.evaluate() Web API, which implements the full XPath 1.0 specification including axes
(descendant::, following-sibling::, etc.), predicates,
node-set functions (last(), position(), count()), and string functions
(contains(), starts-with(), normalize-space()).
Switch between XML and HTML mode at the top of the page. XML mode parses your input as application/xml and surfaces parse errors. HTML mode parses with the lenient HTML parser and is best when extracting data from scraped pages.
XPath Quick Reference
| Syntax | Meaning | Example |
|---|---|---|
| / | Selects from the root | /bookstore/book |
| // | Anywhere in the document | //book |
| @attr | Selects an attribute | //book/@category |
| [n] | 1-based positional predicate | //book[1] |
| [last()] | Last matching node | //book[last()] |
| [@a='v'] | Attribute equality | //book[@category='fiction'] |
| contains() | Substring match | //a[contains(@class,'active')] |
| text() | Text node child | //title/text() |
| | | Union of two node-sets | //title | //author |
| axis:: | Explicit axis selector | //book/following-sibling::book |
How to Use the XPath Tester
- Pick XML or HTML mode at the top of the page depending on your input.
- Paste your document into the Input textarea, or click Load Sample to load the bookstore (XML) or page layout (HTML) example.
- Type an XPath expression into the XPath Expression field — for example
//book/titleor//a[contains(@class,'active')]. - Matched nodes appear immediately in the Result panel, each with its node type, position-aware path, and serialized value.
- Click any item in the Sample Expressions grid to apply a common query, or use the small copy icon to copy the expression.
- Click the Copy button at the top of the Result panel to copy all matched values to your clipboard.
Frequently Asked Questions
What is XPath?
XPath is a W3C-standardized query language for selecting nodes inside an XML or HTML document. It is the basis for transformations in XSLT, querying in XQuery, and selectors in tools like Selenium, Scrapy, lxml, libxml2, and the browser DOM. This tester evaluates expressions against the same engine your browser already ships.
Which XPath version is supported?
Browsers implement XPath 1.0, which is what this tool uses. XPath 2.0
and 3.x features (regex matching, sequences, if/then/else, etc.) are not available
natively in any browser. For XPath 2.0+ you would need a server-side engine such as Saxon.
Is my data sent to a server?
No. Parsing and evaluation happen entirely in your browser using the native DOM. Your XML or HTML never leaves your device, making this tool safe for confidential documents, scraped pages, and internal API responses.
Why do my expressions fail on real-world HTML?
Make sure HTML mode is selected. In HTML mode element names are lower-case (HTML5
normalizes tag names), so use //div, not //DIV. Attribute matches are case-sensitive
— use contains(@class,'active') instead of an
exact equality check when classes contain multiple values.
Can I query namespaced XML?
This tester evaluates with a null namespace resolver, so default namespaces are not
automatically honoured. To match elements in a default namespace, use the local-name() function — for example //*[local-name()='entry'].
What is the difference between text() and string()?
text() selects the text-node children of an
element and returns each as a separate node match. string(.) concatenates all descendant text and returns a single scalar string. Use text() when you need each chunk separately, string() when you want the full visible text.
How do I get the last item?
Use [last()] — for example //book[last()] matches the final book element
in document order. To get the count of matches use the count() function in a wrapping expression like count(//book), which returns a scalar number.