Query XML with XPath

Extract matching elements from XML with simple XPath-style paths and indexes.

freeworks offlinenothing uploaded
ToolXML XPath Query
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

XML is parsed into an object tree, then slash-separated names, wildcard segments, and simple numeric predicates are walked. Matching nodes are rebuilt as XML fragments; this is a limited evaluator rather than a namespace-aware XPath engine.

  • A root slash and element paths cover common extraction.
  • Indexes are one-based to match XPath positions.

Worked example

Find all admin users by role attribute
Use XPath attribute filter to extract user elements with role='admin'
Input
											<root>
  <users>
    <user id="1" role="admin"><name>Alice</name></user>
    <user id="2" role="user"><name>Bob</name></user>
    <user id="3" role="admin"><name>Carol</name></user>
  </users>
</root>
										
Output
												Results: <root>
  <users>
    <user id="1" role="admin">
      <name>Alice</name>
    </user>
    <user id="2" role="user">
      <name>Bob</name>
    </user>
    <user id="3" role="admin">
      <name>Carol</name>
    </user>
  </users>
</root>
Count: 1
											

When to use this

SOAP responses, RSS feeds, and XML migration previews query nodes.

Edge cases

  • Namespace prefixes can be treated as literal keys rather than resolved URIs.
  • Unsupported predicates are not evaluated like full XPath.
  • Repeated siblings need an index or wildcard to select the intended node.

References