XML Minify — Compress and Reduce XML Size Online

🔒 Runs in your browser — nothing is sent to a server

XML minify any pretty-printed or hand-formatted XML into the smallest valid representation in a single click. Paste a SOAP envelope, an SVG, an Office Open XML part or any XML blob, and this XML minifier validates the syntax with the browser's native `DOMParser`, strips whitespace between tags, removes comments by default and emits a single-line document. CDATA sections, the XML declaration, DOCTYPE and `xml:space="preserve"` blocks are left untouched; mixed-content elements stay intact unless you opt into Aggressive mode. Everything runs 100% inside your browser; your input never leaves your device, nothing is uploaded, logged or sent to any server.

Two-pane view: input and output side by side
Copied!

When to use an XML minifier

You reach for an XML minifier any time an XML document needs to travel across a constrained channel: a SOAP API where every kilobyte counts toward CDN bills, an SVG sprite baked into a CSS bundle whose size affects Lighthouse scores, an `.xlsx` part being repackaged before upload, an RSS feed served at high QPS, or an Android resource being squeezed before shipping. Browser-local minification means the payload never touches a server during the transform — important when the XML carries SAML assertions, signed envelopes, tokens or PII you would rather not leak to a remote tool.

How XML minifying works under the hood

XML minifying is a three-step pipeline. First the input is scanned for the XML declaration and the DOCTYPE — both live outside the document tree, so they are pulled aside before parsing and re-attached to the output. Second the remainder is fed through `new DOMParser().parseFromString(input, "text/xml")`; a `parsererror` element in the result triggers a clear error message with the offending line and column. Third a recursive tree walker re-emits every element with no whitespace between sibling tags, drops comments unless asked to keep them, and leaves CDATA, `xml:space="preserve"` and mixed-content elements untouched. Aggressive mode bypasses that last guard. The whole pipeline runs inside the browser, so a multi-megabyte XML document minifies in milliseconds without leaving your tab.

Examples

Input
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1">
    <title>Atlas</title>
    <author>A. Reyes</author>
  </book>
  <book id="2">
    <title>Vesper</title>
    <author>I. Park</author>
  </book>
</catalog>
Output
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="1"><title>Atlas</title><author>A. Reyes</author></book><book id="2"><title>Vesper</title><author>I. Park</author></book></catalog>
XML minify — pretty-printed catalog into one line
Input
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="10"/>
  <line x1="2" y1="12" x2="22" y2="12"/>
</svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/></svg>
Compress XML — SVG with namespaces and self-closing tags
Input
<?xml version="1.0"?>
<tool>
  <name>xml minify</name>
  <role>compress xml for transport</role>
  <client>free-converter.online</client>
</tool>
Output
<?xml version="1.0"?><tool><name>xml minify</name><role>compress xml for transport</role><client>free-converter.online</client></tool>
Remove whitespace XML — payload that names the tool itself
Input
<config>
  <!-- production settings -->
  <script><![CDATA[if (a < b) { x = 1; }]]></script>
</config>
Output
<config><script><![CDATA[if (a < b) { x = 1; }]]></script></config>
XML minifier — comment stripped, CDATA preserved verbatim

FAQ

How do I minify an XML document?

Paste the formatted or hand-written XML into the input above and click Minify. The XML minifier parses your input through the browser's native `DOMParser`, walks the resulting document tree and re-emits every element with no whitespace between tags. Comments are stripped by default; tick "Keep comments" to preserve them. Errors surface with the offending line and column.

What is XML minification?

XML minification rewrites an XML document with every byte of optional whitespace between tags removed, comments stripped, and the entire structure on a single line. The DOM tree and the data are unchanged: every element, attribute, text node and CDATA section stays exactly as it was. Minified XML parses back to the same DOM as the original.

Why should I compress XML before sending it over the network?

Minified XML is typically 30–50% smaller than its pretty-printed equivalent — pretty-printing inflates SOAP envelopes, SVG sprites and `.xlsx` parts with line breaks and indents that have no semantic value. Stripping that whitespace cuts CDN egress, lowers mobile data costs and speeds up first-byte time. Gzip on top of minified XML compounds the saving further.

Will the XML minifier break mixed content like <p>Hello <b>world</b>!</p>?

No. Mixed-content elements — those holding both significant text and child elements — are preserved verbatim by default because the whitespace between text and tags is part of the rendered output. The same rule applies to any element marked `xml:space="preserve"`. Aggressive mode (off by default) strips that whitespace too; the tooltip warns it can break XHTML and SVG semantics.

How is XML minify different from XML beautify?

XML minify and XML beautify are exact opposites. Minify strips whitespace between tags and removes comments to produce the shortest valid XML for transport or storage. Beautify adds line breaks and indentation back so a human can read the document. The DOM tree is identical in both directions; only the cosmetic whitespace around tags differs.

Does the minifier preserve the XML declaration and DOCTYPE?

Yes. The `<?xml version="1.0" encoding="UTF-8"?>` declaration is detected on the first line of the input and re-emitted unchanged at the top of the output. Any `<!DOCTYPE …>` declaration is preserved next. Both belong outside the document tree, so they are extracted before parsing and re-attached during serialisation. Only the newline after the declaration is dropped.

How are CDATA sections handled?

`<![CDATA[…]]>` sections are preserved character-for-character. The minifier treats the content inside CDATA as opaque — every byte stays exactly as it was, even when the contents contain whitespace, line breaks or characters that look like markup. This is essential for embedded scripts, SQL fragments and signed XML where any content drift would invalidate a signature.

Is it safe to paste sensitive XML into this minifier?

Yes — the XML minifier runs entirely in your browser using the native `DOMParser` and a tree walker written in plain TypeScript. Your input and the minified output stay on your machine; nothing is uploaded, logged or cached. Safe for SOAP envelopes containing tokens, SAML assertions, signed payloads and internal config files.

Glossary

XML (Extensible Markup Language)

XML is a text-based, tag-oriented format for representing structured data, defined by the W3C XML 1.0 spec. It powers SOAP and WS-* web services, RSS and Atom feeds, Office Open XML (`.docx`, `.xlsx`), Android layouts, SVG, configuration files and countless legacy enterprise systems. An XML minifier removes optional whitespace from any valid XML document without altering the data it represents.

XML minifier

An XML minifier is any tool or function that strips optional whitespace between tags, drops comments and emits the smallest valid representation of an XML document. Browser `DOMParser` plus a custom tree walker, command-line `xmllint --noblanks` and editor packages such as Prettier can all minify XML. Browser-local minifiers keep secrets in SOAP and SAML payloads off remote servers.

Whitespace in XML

In XML, whitespace between tags is sometimes significant and sometimes not. Whitespace inside element-only content (no text nodes between tags) is cosmetic — the parser ignores it. Whitespace inside mixed content or inside an element with `xml:space="preserve"` is significant — it appears in the rendered output. A safe XML minifier strips only the cosmetic whitespace and leaves the significant whitespace alone.

Mixed content

Mixed content is an XML element that holds both significant text and child elements — for example `<p>Hello <b>world</b>!</p>`. Whitespace between text and tags is part of the rendered output, so a minifier must not collapse it under default settings. Aggressive mode strips whitespace inside mixed-content elements too, but the trade-off is that XHTML, SVG `<text>` and similar formats may render differently.

CDATA section

`<![CDATA[ … ]]>` is the XML escape hatch for embedding text that contains characters which would otherwise need to be escaped — `<`, `>`, `&`, JavaScript and SQL snippets, or arbitrary scripted content. A correct XML minifier never reformats the contents of a CDATA section; it only strips whitespace before the opening `<![CDATA[` and leaves everything inside untouched.

XML declaration

The XML declaration is the optional first line of an XML document — `<?xml version="1.0" encoding="UTF-8"?>` — that pins the XML version and the character encoding. It is not part of the document tree, so a minifier extracts it before parsing and re-emits it at the top of the output. Only the newline that often follows the declaration is dropped.

Related tools