XML Filter

Searches an XML document at every depth for elements whose tag name contains a given text, and collects just those elements (with their full subtrees) under a single results root, useful for pulling one kind of record out of a large, mixed document. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

A large, mixed XML document often has exactly one kind of element you actually care about, buried among many others. This tool pulls just that kind out, wherever it appears.

It's faster than manually scanning or writing an XPath query when you just need everything named a certain thing.

What Is XML Filter?

A tag-name filter that searches the entire parsed document tree, at every depth, for elements whose tag name contains your search text.

It collects the matches, with their full subtrees intact, under a single synthetic root.

How XML Filter Works

The document is parsed into a tree, then walked recursively; every element whose tag name contains the query (case-insensitive) is collected into a results list, and the walk continues into that element's children too, so nested matches are also found.

The collected matches are wrapped in a synthetic <results> root and pretty-printed, since XML requires exactly one root element.

When To Use XML Filter

Use it to pull every instance of one kind of record out of a document that mixes several different element types.

It's also useful for a quick, low-effort alternative to writing an XPath query when you just need everything named a certain thing.

Often used alongside XML Key Finder, XML Flattener and XML Truncator.

Features

Advantages

  • Searches every depth, not just the top level.
  • Keeps each match's full subtree intact.
  • Runs entirely client-side.

Limitations

  • Matches by tag name only, not by attribute or text content.
  • A matched element's own nested matches are still collected separately too, so a tag search that matches both a parent and its child produces both as separate top-level results (the child appears twice: once inside its parent's subtree, once as its own top-level match).

Examples

Filtering for one tag name

Input

<catalog><item>a</item><note>x</note><item>b</item></catalog>

Output

<results>
  <item>a</item>
  <item>b</item>
</results>

Searching for "item" keeps both matching elements and drops the unrelated <note>.

Best Practices & Notes

Best Practices

  • Use a specific enough search term to avoid matching unrelated tags that happen to share a substring.
  • Follow up with the XML Prettifier if you want different indentation on the filtered result.
  • Check the match count first, an unexpectedly high number usually means the search term is too broad.

Developer Notes

Filtering is a single recursive collection pass over the parsed tree; matched elements are pushed by reference (not deep-cloned per match), then the whole set is re-serialized once with `toPrettyXml`.

XML Filter Use Cases

  • Pulling every instance of one record type out of a large mixed document
  • Quickly checking how many elements of a given tag name exist, and where
  • Extracting a subset of a document for a smaller test fixture

Common Mistakes

  • Using a search term that's too generic and matches unrelated tags sharing the same substring.
  • Expecting duplicate parent/child matches to be deduplicated, they intentionally aren't.

Tips

  • If you need results by attribute or content value instead of tag name, try Find XML Values or Find XML Keys instead.
  • Check the FAQ above if the output doesn't look like what you expected.

References

Frequently Asked Questions