XML Statistics Generator

Parses an XML document and reports element, attribute, text-node, and comment counts, maximum nesting depth, byte size, and a sorted table of how often each tag name appears — a deeper structural profile than a basic validity check. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

Knowing whether an XML document is well-formed answers one question; knowing its shape, how many elements it has, how deep it nests, which tags repeat most, answers a different one. This tool focuses on the second question.

It's useful for sanity-checking a generated document, understanding an unfamiliar XML file before writing code against it, or confirming a batch export contains the number of records you expect.

What Is XML Statistics Generator?

A structural analysis tool that walks a parsed XML document once and tallies element, attribute, text-node, and comment counts, tracks maximum nesting depth, and builds a frequency table of every distinct tag name.

It shares its underlying parser with the rest of this category's tools, so a document that validates here will validate identically elsewhere in the XML Tools set.

How XML Statistics Generator Works

The input is parsed into a tree with the same stack-based parser the Validator and Prettifier use, then a single recursive walk increments counters per node type and records each element's tag name in a frequency map.

The frequency map is sorted by count descending (ties broken alphabetically) before display, so the most common tags surface first.

When To Use XML Statistics Generator

Use it after generating XML programmatically, to confirm the record count and structure match expectations.

It's also useful when picking up an unfamiliar XML file, to get a quick sense of its scale and dominant element types before writing a parser or XPath query against it.

Features

Advantages

  • Runs entirely client-side, so sensitive documents never leave your browser.
  • Goes beyond a pass/fail validity check with counts that reveal actual document shape.
  • The tag-frequency table surfaces the dominant repeated element without manual counting.

Limitations

  • Only reports well-formedness-level structure, not schema conformance.
  • Whitespace-only text nodes are intentionally excluded from the text count, which can understate total text-node count if you're specifically interested in formatting whitespace.
  • Very large documents (tens of megabytes) may take a moment, since the whole tree is walked in memory.

Examples

A small document's tag frequency

Input

<items><item>a</item><item>b</item><item>c</item></items>

Output

item: 3, items: 1

The repeated <item> tag dominates the frequency table, confirming three records.

Best Practices & Notes

Best Practices

  • Check tag frequency after a bulk export to confirm the expected record count.
  • Pair with the XML Visualizer when a stat looks off and you need to see exactly where in the tree it comes from.
  • Run this before writing an XPath or parser against unfamiliar XML, to know what you're dealing with.

Developer Notes

Stats are computed with a single tree walk that also builds a `Map<string, number>` for tag frequency, converted to a sorted array only at the end, so the hot path stays O(n) regardless of how many distinct tag names exist.

XML Statistics Generator Use Cases

  • Confirming a generated XML export has the expected number of records
  • Getting a quick structural overview of an unfamiliar XML file
  • Spotting an unexpectedly deep or duplicated section before debugging further

Common Mistakes

  • Expecting the text-node count to include whitespace-only formatting text, it's filtered out on purpose.
  • Treating the tag-frequency table as a schema validator, it reports what's present, not what's allowed.

Tips

  • Sort order is most-frequent first, scan the top of the list to find the dominant record type quickly.
  • Use alongside the XML Validator when you need both a pass/fail check and a structural breakdown.

References

Frequently Asked Questions