Skip to content
Browser tool Runs locally

XML Minifier

Remove unnecessary formatting whitespace from XML while preserving meaning. Runs locally.

XML input
0 chars
Minified XML
Minified XML will appear here.

What is XML minification?

XML minification removes whitespace that exists only for readability - the newlines and indentation a human adds between tags - without touching the data the document actually carries.

Whitespace and newline behavior

Only whitespace-only text nodes between purely structural tags are removed - the kind of newline-plus-indentation that sits between a closing tag and the next opening tag with nothing else in between. Whitespace that's part of an element's actual text content, including a single space that matters inside a sentence, is left exactly as written, since removing it would change what the document says, not just how it looks.

What stays protected

  • Whitespace inside text content.
  • Mixed content, where an element has both text and child elements.
  • xml:space="preserve" subtrees.
  • CDATA sections and comments.

Practical use cases

Minifying is most useful right before XML crosses a network boundary or gets stored at scale: trimming an API request or response payload, compacting a configuration file that's bundled into a build, or producing a canonical, whitespace-free form of a document for hashing or byte-for-byte comparison. In all of these, the formatting whitespace was only ever there to help a person read the file - once it's machine-to-machine, it's pure overhead.

Common mistakes and limitations

  • Expecting a dramatic size reduction on dense XML - if the input already has little or no indentation, there's little formatting whitespace to remove, so the output can end up close to the same size.
  • Assuming minified XML is still easy to read - minification trades readability for compactness on purpose; keep an original, formatted copy if the file will need hand-editing later.
  • Treating minification as compression - it doesn't reduce the size of the actual data, only removes formatting characters; for real bandwidth savings on top of that, the output still benefits from being gzipped or otherwise compressed in transit.
  • Forgetting that xml:space="preserve" opts a subtree out - any element marked this way keeps its whitespace untouched, so a document mixing preserved and non-preserved sections won't shrink uniformly.

Frequently asked questions

What does XML minification remove?
It removes whitespace-only text nodes that exist purely for indentation and readability - the newlines and spaces between structural tags that have no element text between them. Text content itself, and whitespace that's part of that text, is left untouched.
Is minifying the same as gzip or other compression?
No. Minification is a change to the text itself - it produces smaller, still human-readable-if-dense XML by removing formatting characters. Gzip and similar tools are binary compression applied on top of the text, usually during network transfer, and work on any content regardless of whether it's already minified. The two are complementary, not substitutes for each other.
Why is the output sometimes not smaller than the input?
If the input already has no removable formatting whitespace - for example, XML that's already on one line, or where every element contains meaningful text with no indentation between tags - there's nothing to strip, so the output matches the input.
Does minifying change mixed content or text formatting?
No. Whitespace inside text content, and mixed content where an element contains both text and child elements, is preserved exactly as written. Only whitespace-only text nodes sitting between purely structural tags are removed.
Does minification respect xml:space="preserve"?
Yes. Any element marked with xml:space="preserve" keeps its whitespace exactly as-is, along with its descendants, unless a nested element explicitly overrides it back to default handling.

Related tools