Compact Mode, the switch next to Load Example below, removes the whitespace a pretty-printer adds between tags — the newline and indentation after a >, before the next <. It does this with a narrow rule rather than a full XML-aware rewrite: only whitespace that sits strictly between two tags is touched. Whitespace inside a text node's own content, inside an attribute value, or inside a CDATA section is left exactly as it was, because that whitespace can be part of the data rather than formatting.
The SOAP-shaped example below is loaded in the editor above. Toggle Compact Mode to see it collapse from the pretty-printed form to the single line shown here — an 18% reduction on this sample, computed the same way for whatever you paste in.
Before and after
This is loaded in the editor above with Compact Mode off. Toggle it on to see this exact transform happen live.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<AuthToken>a1b2c3d4</AuthToken>
</soap:Header>
<soap:Body>
<GetOrderResponse xmlns="http://example.com/orders">
<Order id="4821">
<Customer>Ana Torres</Customer>
<Items>
<Item sku="SKU-100" qty="2">Widget</Item>
<Item sku="SKU-204" qty="1">Gadget</Item>
</Items>
<Total currency="BRL">259.80</Total>
</Order>
</GetOrderResponse>
</soap:Body>
</soap:Envelope><?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><AuthToken>a1b2c3d4</AuthToken></soap:Header><soap:Body><GetOrderResponse xmlns="http://example.com/orders"><Order id="4821"><Customer>Ana Torres</Customer><Items><Item sku="SKU-100" qty="2">Widget</Item><Item sku="SKU-204" qty="1">Gadget</Item></Items><Total currency="BRL">259.80</Total></Order></GetOrderResponse></soap:Body></soap:Envelope>564 bytes → 463 bytes — a 18% reduction on this sample.
How it works
What stays untouched, and why that is the safe default
A comment (<!-- ... -->) and a CDATA section (<![CDATA[ ... ]]>) can both legitimately contain the characters < and > as data, not markup — a CDATA block is exactly how you embed a snippet of HTML or JavaScript inside XML without escaping it. The whitespace-collapsing rule here only ever matches a literal > immediately followed by whitespace and a literal <, so it never reaches inside either construct to rewrite what is, semantically, a string.
<script><![CDATA[if (a < b) { x(); }]]></script>Mixed content is usually safe, with one real exception
Prose-like XML — an element whose text and child tags are interleaved, like <p>Preheat oven to <b>220</b> degrees.</p> — survives minification unchanged whenever there is real text touching the tag boundary on at least one side, which covers the overwhelming majority of real documents.
The one case where this goes wrong is deliberate, whitespace-only content under xml:space="preserve" — an element whose entire point is that its whitespace matters and there is no other content to anchor it to. There, an element like <code xml:space="preserve"> </code> loses its three spaces entirely, because to this rule they look identical to formatting indentation. This is listed under Known limitations below because it is a real, demonstrated case, not a hypothetical one.
What Compact Mode does not do
It does not touch whitespace inside a tag itself — extra spaces between attributes, like <a b="1" c="2" />, are left as written, since collapsing those risks looking like a different kind of edit than "remove formatting." It also does not remove comments or processing instructions; if you want those stripped too, that is a separate, more invasive transform this switch does not perform.
Known limitations
- A whitespace-only text node inside an element marked xml:space="preserve" is collapsed away like any other inter-tag whitespace, even though it is meant to be preserved. This is a real, verified limitation — <code xml:space="preserve"> </code> becomes <code xml:space="preserve"></code> — not a hypothetical edge case.
- Attribute spacing, comments, and processing instructions are left exactly as written; if your document has redundant spacing inside a tag, this switch will not remove it.
Minify XML FAQ
Will minifying break a CDATA section?
No. CDATA content is never touched, including angle brackets inside it — the rule only matches whitespace that sits strictly between a > and a < at the tag level, never inside CDATA delimiters.
Is it safe for documents with mixed text and tags, like HTML-ish XML?
In almost every case, yes — as long as there is real text next to the tag boundary. The one documented exception is a whitespace-only xml:space="preserve" element, listed under Known limitations.
Does minifying save as much as gzip already would?
Less than the raw byte count suggests, if the response is already compressed — gzip handles repeated whitespace efficiently on its own. Minifying matters most for payloads that are not compressed, like some SOAP requests and internal service calls.
Is my XML sent anywhere?
No. Formatting and minifying both run in your browser. Nothing is uploaded, which matters since XML payloads like the SOAP example above often carry internal service names.
Other XML tools
Need the full formatter, without a specific guide attached? The general XML formatter has the same beautifier and Compact Mode switch.