XML Minifier
Collapse XML whitespace and strip comments to produce the smallest valid document. Browser-only.
0 characters
0 characters
About XML Minifier
The XML minifier removes whitespace between elements and strips XML comments to produce a compact, single-line document. Whitespace inside element text is preserved — only the indentation and line breaks between tags are removed. The result is byte-for-byte smaller and parses to the same XML infoset (excluding comments).
When to use it
- Reducing the size of an XML payload before transmission
- Embedding XML inside a JSON string or a single-line config value
- Producing canonical XML for hashing or signing (combine with a c14n step if signatures are required)
- Stripping comments before sharing XML publicly
How it works
A pair of regex passes removes XML comments (<!-- ... -->) and collapses whitespace between adjacent tags (> <). Whitespace inside element text content is preserved exactly — only inter-tag whitespace is touched. Use the XML formatter to verify the round-trip.
Examples
Whitespace and comments removed
<root>
<!-- a comment -->
<a>
<b>hi</b>
</a>
</root><root><a><b>hi</b></a></root>
Frequently asked questions
- Does minifying change the data?
- The element structure and text content are unchanged. Whitespace between elements is removed and comments are dropped. If you need to preserve comments, use a different tool.
- What about whitespace inside text nodes?
- Preserved as-is. Only whitespace between adjacent tags is collapsed. <p>Hello world</p> stays exactly as is.
- Is the output still valid XML?
- Yes — for well-formed input. The minifier does not parse the XML, so malformed input produces malformed output. Run it through the XML formatter first if you want to confirm validity.
- How much smaller will my XML be?
- Heavily indented XML can shrink by 30–50%. Documents with mostly text content and few nested elements shrink only slightly.