DevBolt
Processed in your browser. Your data never leaves your device.

How do I test XPath expressions against XML online?

Paste your XML into the editor, type an XPath expression like //book[@category='programming']/title, and click Evaluate to see matching nodes instantly. The tool supports element selection, attribute filtering, axes (ancestor, descendant, sibling), and XPath functions (count, contains, starts-with). Click any example query button to try common patterns. Everything runs in your browser using the native XPath 1.0 engine — no data is sent to a server.

← Back to tools

XPath Tester

Test XPath expressions against XML data with real-time evaluation. Extract elements, filter by attributes, and navigate XML document structures.

XPath Reference
ExpressionDescription
/Root element
//elementAll matching elements anywhere
./childDirect child of context
@attrAttribute value
[1]First element (1-indexed)
[last()]Last element
[position()<3]First two elements
[@attr='val']Filter by attribute
[contains(., 'text')]Contains text
[starts-with(@id, 'x')]Starts with
text()Text content
node()Any node
count(//el)Count elements
sum(//el)Sum of numeric values
string-length(//el)String length
ancestor::elAncestor axis
descendant::elDescendant axis
following-sibling::elFollowing siblings
parent::elParent axis
el1 | el2Union of two node sets
About XPath

XPath (XML Path Language) is a query language for selecting nodes from XML documents. It uses path expressions to navigate through elements, attributes, and text in an XML tree structure.

Key concepts:
  • Nodes — elements, attributes, text, comments, and the document itself
  • Axes — define the direction of navigation (child, parent, ancestor, descendant, sibling)
  • Predicates — filter nodes with conditions inside square brackets
  • Functions — built-in string, number, and node functions (contains, count, sum, etc.)

XPath is used in XSLT, XQuery, web scraping (Selenium, Puppeteer), configuration parsing, and XML data extraction. This tool uses your browser's built-in XPath 1.0 engine — no data is sent over the network.

Frequently Asked Questions

What is XPath and how does it work?
XPath (XML Path Language) is a query language for selecting nodes from XML documents. It uses path expressions — similar to file system paths — to navigate through the hierarchical tree structure of an XML document. XPath 1.0 is built into every modern browser and supports selecting elements, attributes, text nodes, and computing values with built-in functions like count(), contains(), and string-length(). XPath is used in XSLT transformations, XQuery, web scraping tools (Selenium, Puppeteer), and XML configuration parsing.
What is the difference between XPath and JSONPath?
XPath queries XML documents while JSONPath queries JSON data. XPath is a W3C standard with a formal specification, supports axes (ancestor, descendant, sibling), has built-in functions (count, sum, contains, string-length), and can select attributes with @. JSONPath is loosely modeled after XPath but has no formal standard — it uses $ for root (vs / in XPath), .. for recursive descent (vs // in XPath), and [?(@.field)] for filters (vs [@attr] in XPath). XPath is more powerful but only works with XML; JSONPath is simpler but limited to JSON structures.
How do I select elements by attribute value in XPath?
Use square bracket predicates with the @ symbol: //element[@attribute='value'] selects all elements with that attribute value. You can also use functions: //element[contains(@class, 'active')] for partial matches, //element[starts-with(@id, 'item-')] for prefix matches, and //element[@count > 5] for numeric comparisons. Multiple predicates can be chained: //book[@category='fiction'][@lang='en']. To select the attribute itself rather than the element, use //element/@attribute.
Is it safe to paste XML data into this tool?
Yes. This XPath tester runs entirely in your browser using the built-in DOMParser and document.evaluate() APIs. Your XML data is never sent to any server — all parsing and XPath evaluation happens client-side in JavaScript. You can verify this by opening your browser's Network tab and confirming no requests are made when you evaluate expressions. This makes it safe for testing XPath queries against XML that contains API responses, configuration files, or other sensitive data.

Related Inspect Tools