XPath Tester

Query XML documents using XPath expressions.

XPath Examples
/ - Root element
/bookstore - Root element named 'bookstore'
/bookstore/book - All book elements under bookstore
//book - All book elements anywhere
/bookstore/book[1] - First book element
/bookstore/book[last()] - Last book element
/bookstore/book[position()<3] - First two books
//title[@lang] - All titles with lang attribute
//title[@lang='en'] - Titles with lang='en'
/bookstore/book[price>35] - Books with price > 35
//book/title | //book/price - All titles and prices
//@lang - All lang attributes
//title/text() - Text content of all titles
count(//book) - Count of all books
sum(//book/price) - Sum of all prices
Sample XML

What Is XPath?

XPath (XML Path Language) is a query language for selecting nodes from XML documents. It uses path expressions to navigate through the hierarchical structure of an XML document, similar to how file paths navigate a file system. XPath is a W3C standard and is widely used in XSLT, XQuery, web scraping, and automated testing frameworks like Selenium.

How to Use This Tool

  1. Paste your XML document into the XML Input field, or click Load Sample for an example.
  2. Enter an XPath expression in the XPath Query field.
  3. Click Query to see matching nodes in the output.
  4. Use the example expressions for common patterns.

Common Use Cases

  • Web Scraping: Extract specific data from HTML/XML pages using XPath selectors in tools like Scrapy or Puppeteer.
  • XSLT Transformations: Select and transform XML nodes during stylesheet processing.
  • Automated Testing: Locate web elements in Selenium and other testing frameworks using XPath locators.
  • Configuration Parsing: Query XML configuration files (web.config, pom.xml, etc.) for specific settings.
  • API Response Validation: Validate SOAP/XML API responses by querying specific elements.

Frequently Asked Questions

CSS selectors are simpler and faster for basic element selection in HTML. XPath is more powerful — it can navigate up the document tree (parent/ancestor axes), use complex predicates, and work with XML namespaces. XPath is the better choice for XML documents and complex queries.

The double slash (//) is a shorthand for the descendant-or-self axis. It selects nodes anywhere in the document regardless of their depth. For example, //title finds all <title> elements at any level of nesting.

Yes, but the HTML must be well-formed (valid XHTML) or parsed by an HTML-tolerant parser first. Most web scraping tools and browser developer consoles support XPath on HTML documents.