Test XPath Queries on XML
Write and debug XPath expressions directly in your browser. Paste your XML, write a query, and instantly see the matched nodes and results.
Enter XML and XPath query, then click Evaluate
About XPath
XPath (XML Path Language) is a query language for selecting nodes from an XML document. Use // for descendant selection,[@attribute] for attribute filtering, and functions like count(),contains(),position() for advanced queries.
How It Works
This XPath tester lets you evaluate XPath expressions against your XML document directly in the browser. It uses the browser's native DOMParser and XPathEvaluator APIs to process queries without sending your data to any server.
The evaluation process:
- Parse XML: Your XML input is parsed into a DOM document structure.
- Compile XPath: The XPath expression is compiled into an executable query.
- Evaluate: The query runs against the DOM, returning matching nodes or values.
- Display results: Matched nodes, their count, and values are shown with highlighting.
The tool supports XPath 1.0 functions like count(), text(), contains(), and positional predicates. Results update instantly as you type, making it easy to debug complex expressions.
When You'd Actually Use This
Debugging XPath in XSLT stylesheets
You're writing an XSLT transformation and the select attribute isn't matching. Test the XPath here first before debugging the full stylesheet.
Extracting data from XML feeds
Working with an RSS feed or SOAP response? Build and test the XPath that pulls out exactly the nodes you need.
Learning XPath syntax
Students studying XML technologies can experiment with predicates, axes, and functions to see immediate results.
Validating XML against business rules
Use XPath with count() and boolean functions to check constraints like 'every order must have at least one item'.
Testing XPath in code before deployment
Developers using XPath in Java, .NET, or Python can verify their expressions work correctly before writing unit tests.
Scraping structured XML data
When automating data extraction from XML sources, prototype your XPath queries here to ensure they're robust.
What to Know Before Using
Browser XPath support varies
Most browsers support XPath 1.0. XPath 2.0+ features like regex or advanced functions may not work in all environments.
Namespaces must be declared
If your XML uses namespaces, you need to declare them in the XPath evaluator. Unprefixed elements in namespaced XML won't match without proper setup.
Case sensitivity matters
Element and attribute names are case-sensitive. <Product> and <product> are different elements in XPath.
Position is 1-based, not 0-based
XPath uses 1-based indexing. The first node is position 1, not 0. This trips up JavaScript developers frequently.
Text() vs string values
text() returns text nodes. Using the string value of an element includes all descendant text. Know which one you need.
Common Questions
What's the difference between / and // in XPath?
/ selects from the root or current context. // selects from anywhere in the document. /book/title gets direct children; //title gets all title elements anywhere.
How do I select attributes in XPath?
Use the @ prefix. @id selects the id attribute. //book[@category='fiction'] finds books with category='fiction'.
Can I use logical operators in XPath?
Yes. Use and, or, and not(). Example: //book[price > 10 and price < 50] finds books priced between 10 and 50.
What does the count() function return?
count() returns the number of nodes in a node-set. count(//book) gives the total number of book elements in the document.
How do I handle namespaces in XPath?
You need to register namespace prefixes with the evaluator. In this tool, declare namespaces and use prefixes like ns:element in your XPath.
What's the difference between . and .. in XPath?
. refers to the current node (self). .. refers to the parent node. Use .. to navigate up the tree from your context.
Can XPath modify XML documents?
No. XPath is a query language for selecting nodes, not modifying them. Use XSLT or DOM manipulation for changes.
Other Free Tools
XML Formatter and Validator
Format and Validate Your XML Instantly
XML to JSON Converter
Convert XML to JSON Online
XML Minifier and Compressor
Minify and Compress XML Files
XML Viewer and Editor
View and Edit XML Online
ASCII to Hex Converter
ASCII to Hex Converter: Text to Hexadecimal Translator
Barcode Generator
Free Barcode Generator
Binary to Text Converter
Binary to Text Converter
Free Printable Calendar Maker
Create & Print Your Custom Calendar
Pie Chart Maker
Free Pie Chart Maker Online