Dad’s Data formats tools

XPath Tester

Evaluate XPath 1.0 expressions against XML using the browser DOM API. Runs 100% locally.

XML
XPath / Results
Expression

XPath 1.0 examples

All book elements
Books with a specific attribute
Text content of all titles
Count nodes
Nodes with a numeric predicate

XPath 1.0 expression anatomy

XPath is a path language for selecting nodes in an XML document. The browser DOM API supports XPath 1.0, which covers the vast majority of practical query needs. Understanding the core syntax unlocks most use cases without needing a full spec.

//book[@genre='fiction']/title
// — anywhere in the document
book — element name
[@genre=…] — attribute predicate
/title — child element

Common XPath patterns

ExpressionSelectsNotes
//elementAll elements anywhere in the documentTwo slashes = descendant search
/root/childDirect child onlySingle slash = absolute path from root
//book[@genre]Elements with a specific attribute presentAttribute existence predicate
//book[@id="3"]Elements with a specific attribute valueEquality predicate
//item[position()=1]First item in each parentPosition predicate (1-indexed)
//book/text()Direct text content of elementstext() selects text nodes
//book/@titleAttribute value@name selects attributes

Static expression reference

Query all book titles with genre='fiction'
Input
<library>
  <book genre="fiction">
    <title>Dune</title>
  </book>
  <book genre="science">
    <title>A Brief History</title>
  </book>
</library>
Output
XPath: //book[@genre='fiction']/title

Result: Dune

What results can look like

  • Node set: a list of matching elements or attributes — the most common result type.
  • String: when you select text() or @attribute, results are string values.
  • Number: XPath functions like count() and sum() return numeric results.
  • Boolean: predicates like [contains(.,"x")] produce true/false internally.
Tip: Start with //elementName to find all matching elements, then add predicates to filter. That iterative approach is faster than writing a complex path from scratch.

XPath 1.0 limits and quirks

Your files stay on your computer. Dad promised.

Data formats tools

Search the Data formats tools