Skip to content
πŸ› οΈToolsShed

XPath Tester

Test XPath expressions against XML documents.

No matching nodes

About this tool

XPath is a powerful query language for navigating and extracting data from XML documents. This tool lets you test XPath expressions directly in your browser without needing server-side tools or complex IDE setups. Whether you're working with configuration files, data feeds, or API responses in XML format, XPath Tester helps you find and validate the exact elements you need quickly.

To use the tool, paste or type your XML document into the editor, then write your XPath expression in the query field and execute it. The tool immediately displays all matching elements, highlighting exactly what your expression selects. You can refine your query in real time to navigate nested structures, filter by attributes, or extract specific text content.

Frequently Asked Questions

Code Implementation

from lxml import etree

xml_text = """<?xml version="1.0"?>
<bookstore>
  <book category="cooking">
    <title>Everyday Italian</title>
    <price>30.00</price>
  </book>
  <book category="web">
    <title>Learning XML</title>
    <price>39.95</price>
  </book>
</bookstore>"""

root = etree.fromstring(xml_text.encode())

# Basic XPath queries
titles = root.xpath("//book/title/text()")
print("All titles:", titles)

# Predicate filter
web_books = root.xpath("//book[@category='web']/title/text()")
print("Web books:", web_books)

# Aggregate function
prices = root.xpath("//price/text()")
total = sum(float(p) for p in prices)
print(f"Total: {total:.2f}")

# Namespace example
NS = {"ns": "http://www.example.com/ns"}
# root.xpath("//ns:book", namespaces=NS)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.