XML Compressor & Whitespace Remover
Paste XML and instantly remove unnecessary whitespace, comments, and formatting to reduce file size
Paste any XML — config files, SOAP payloads, SVGs, Maven POMs — and strip out whitespace, comments, and blank lines in one click. The output is the same document, just without formatting characters that inflate file size by 30-50%.
Handy when you need smaller payloads for API calls, leaner configs for CI pipelines, or cleaner SVGs for inline embedding. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool parses your XML character by character. It collapses all whitespace between tags into nothing, removes <!-- comment --> blocks entirely, and trims extra spaces inside text nodes down to a single space. CDATA sections stay untouched — those are literal content and shouldn't be modified. If you check "Remove PIs," it also strips processing instructions like <?xml version="1.0"?>.
Examples
Cleaning Up a Config File
You exported an app config and it's full of indentation and developer comments.
<config>
<!-- Database settings -->
<database>
<host>db.prod.local</host>
<port>5432</port>
</database>
</config>
<config><database><host>db.prod.local</host><port>5432</port></database></config>
Shrinking a SOAP Request Body
SOAP envelopes from code generators tend to be heavily indented. Compressing before sending cuts the payload size by 30-40%.
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetPrice>
<Item>Widget-A</Item>
</GetPrice>
</soap:Body>
</soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetPrice><Item>Widget-A</Item></GetPrice></soap:Body></soap:Envelope>
Stripping Comments and PIs from an SVG
SVG files exported from Illustrator or Inkscape often carry XML declarations, editor comments, and metadata. Remove all of it before embedding in HTML.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape -->
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" />
</svg>
<svg width="100" height="100"><circle cx="50" cy="50" r="40"/></svg>
Who Uses This
Minify XML payloads before sending them through REST or SOAP endpoints to cut response times.
Compress Maven POM files, Spring configs, and deployment descriptors before baking them into container images.
Clean up SVG files exported from design tools so they're smaller when inlined in HTML pages.
Shrink large XML data exports before archiving or transferring them between systems.
Common Mistakes
Some XML schemas treat whitespace inside text nodes as meaningful — poetry markup, code listings, or pre-formatted content. Compressing those will collapse spaces and break the output. Check whether your schema uses xml:space="preserve" before running the compressor.
Checking "Remove PIs" strips <?xml version="1.0" encoding="UTF-8"?>. That's fine for embedding in HTML, but some XML parsers need it — especially when the encoding isn't UTF-8. If your system throws encoding errors after compression, uncheck that option.
This tool does minification, not binary compression. It removes formatting characters. For maximum size reduction on large files, minify first here, then apply gzip or Brotli on your server. The two approaches stack — you'll typically save 30-40% from minification and another 60-70% from gzip on top of that.
Technical Details
- Processing: 100% client-side — no server upload
- Browser Support: Chrome, Firefox, Safari, Edge
- Max Input Size: Limited only by your browser's available memory
- CDATA Handling: Preserved exactly as-is
- Output Format: Single-line minified XML, downloadable as .xml
Frequently Asked Questions
What's the difference between XML compression and XML minification?
People use the terms interchangeably, but technically "minification" means removing whitespace, comments, and formatting to reduce character count. "Compression" usually refers to binary encoding like gzip. This tool does minification. For the best results, minify your XML here and then serve it with gzip compression on your web server.
Does compressing XML change any data or break the document?
No. The compressor only removes characters that don't affect the XML's meaning — whitespace between tags, comment blocks, and optional processing instructions. Every element, attribute, and text value stays identical. The compressed output is semantically the same document.
How much smaller will my XML file get?
Depends on how formatted the original is. A heavily indented file with lots of comments can shrink 30-50%. Something already fairly compact might only drop 5-10%. The tool shows you the exact byte counts and percentage right after you compress.
Is it safe to paste sensitive XML data into this tool?
Yes. Everything happens in your browser with JavaScript. Your XML is never sent to any server, never stored, and never logged. You can turn off your internet connection and the tool still works — that's how you know nothing leaves your machine.
What happens to CDATA sections during compression?
They're left completely alone. CDATA blocks contain literal content that's meant to be read as-is, so the compressor skips over them. Whatever was inside your <![CDATA[...]]> tags before compression will be exactly the same after.