🔍 XPath Tester & Evaluator
Test and evaluate XPath expressions against XML documents.
📋 When to Use the XPath Tester & Evaluator
The XPath Tester & Evaluator is essential for developers working with XML data who need to quickly test XPath queries before using them in code. Use it when debugging XSLT transformations, validating XML data extraction paths, learning XPath syntax, or building web services that query XML payloads. It's perfect for API integration work, configuration file parsing, and automated testing workflows. No data ever leaves your browser — everything processes locally.
⚙️ How the XPath Tester & Evaluator Works
The XPath Tester & Evaluator uses the browser's native document.evaluate() API to run XPath 1.0 expressions against parsed XML documents. When you click Evaluate, the XML is first parsed with DOMParser using the text/xml MIME type. The tool then evaluates your XPath expression using ORDERED_NODE_ITERATOR_TYPE, iterating through each matching node. Each result displays the node type badge (Element, Attribute, Text, Comment, etc.), the generated absolute XPath path with positional predicates for same-name siblings, and the node's text content or attribute value. A namespace resolver automatically extracts xmlns declarations from the root element for namespace-aware queries.
How to Use the XPath Tester & Evaluator
- Paste your XML — Drop any XML document into the XML input area. A sample book catalog is pre-loaded with multiple books, prices, and a namespace prefix to help you get started.
- Enter an XPath expression — Type your XPath query into the input field. Try expressions like
//titlefor all titles,/catalog/book[price>30]for filtered books, orcount(//book)for the total count. - Click Evaluate — The tool parses the XML and runs your XPath expression. Each matched node appears with its generated full path, node type badge, and content.
- Review the results — The results panel shows each match with context. Use the Raw Output section for plain-text results, and the Copy button to export.
- Refine your query — Adjust your XPath and re-evaluate. The tool supports predicates, axes, functions, and namespace prefixes registered in the XML.
Frequently Asked Questions
What XPath version does this tool support?
The tool uses the browser's built-in document.evaluate() API, which implements XPath 1.0. This covers all standard path expressions, predicates, axes (child, descendant, ancestor, following-sibling), and core functions like count(), sum(), contains(), and not().
How are namespaces handled?
The tool automatically detects xmlns declarations on the root element and registers them for namespace-aware queries. When using a namespace prefix, use the same prefix defined in your XML. For example, if your XML declares xmlns:bk="urn:books", use //bk:genre in your XPath.
What node types can I query?
The tool supports all XPath node types: elements, attributes, text nodes, comments, processing instructions, and namespace nodes. Each result displays a color-coded badge indicating the node type.
Can I use XPath functions like count() and sum()?
Yes! The tool supports XPath 1.0 functions including count (returns a number), sum, contains, starts-with, substring, string-length, normalize-space, and not. When the result is a primitive value (number, boolean, string), it displays in the Raw Output section.
Does my XML data leave my browser?
No. All XML parsing and XPath evaluation happens entirely in your browser using native JavaScript APIs. Your data never touches any server or leaves your device.