XML Minifier
Remove whitespace and line breaks from XML, or beautify it back, right in your browser
What is an XML Minifier?
An XML minifier removes the indentation, line breaks, and spacing between tags that make XML easy for people to read but add nothing for machines. The structure of the document stays the same, so you get the same XML in a more compact form.
Minified XML is common in SOAP requests, API payloads, configuration files, and data exchanged between systems, where a smaller message is easier to send, store, or paste as a single line. This tool also includes a Beautify mode, so you can turn compact XML back into a readable, indented layout whenever you need to inspect it.
How to Use This XML Minifier
- Paste your XML into the input box, or click Example to load sample data.
- Choose an action: click Minify XML to remove whitespace, or Beautify to format the XML with indentation.
- Check the size comparison. The Original, Minified, and Saved values show how much smaller the result is.
- Fix any Parse Error. If the XML is not well-formed, the tool shows an error instead of output. See the tips below for common causes.
- Copy or download the result as an
.xmlfile.
Example: Before and After Minifying
The input below is indented with two spaces and spread over several lines.
<catalog>
<book id="1">
<title>XML Basics</title>
<price>9.99</price>
</book>
<book id="2">
<title>Working with Namespaces</title>
<price>14.99</price>
</book>
</catalog>
After minifying, the whitespace between tags is gone and the document fits on one line.
<catalog><book id="1"><title>XML Basics</title><price>9.99</price></book><book id="2"><title>Working with Namespaces</title><price>14.99</price></book></catalog>
| Metric | Value |
|---|---|
| Original | 194 bytes |
| Minified | 161 bytes |
| Saved | 33 bytes (17.0%) |
Savings depend on how much indentation and how many short tags the file has. Deeply nested, heavily indented XML usually saves more than XML that is already compact.
Example: Minifying a SOAP Request
Namespaces, prefixes, and attributes are kept exactly as written. Only the whitespace between tags is removed.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://example.com/orders">
<soapenv:Header/>
<soapenv:Body>
<ord:GetOrderRequest>
<ord:OrderId>10042</ord:OrderId>
<ord:IncludeItems>true</ord:IncludeItems>
</ord:GetOrderRequest>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://example.com/orders"><soapenv:Header/><soapenv:Body><ord:GetOrderRequest><ord:OrderId>10042</ord:OrderId><ord:IncludeItems>true</ord:IncludeItems></ord:GetOrderRequest></soapenv:Body></soapenv:Envelope>
This request goes from 329 bytes to 295 bytes, a saving of 34 bytes (10.3%).
Minify vs Beautify
| Minify | Beautify | |
|---|---|---|
| Goal | Smaller output, no extra whitespace | Readable output with indentation |
| Result | Tags run together, usually on one line | One element per line, indented by depth |
| Best for | Sending, storing, or embedding XML in code or a request | Reading, debugging, and reviewing changes |
| Reversible | Run Beautify to get a readable layout again | Run Minify to compact it again |
Beautify gives you a readable layout, not your original spacing, so keep a copy of the source file if exact formatting matters.
What Changes and What Stays the Same
| Part of the XML | After minifying |
|---|---|
| Indentation and line breaks | Removed |
| Whitespace between tags | Removed |
| Element names and order | Unchanged |
| Attributes and their values | Unchanged; quotes are rewritten as double quotes |
| Namespaces and prefixes | Unchanged |
| Comments | Removed |
| CDATA sections | Converted to escaped text such as < and & |
XML declaration (<?xml ... ?>) | Kept, rewritten with double quotes |
| Whitespace inside text values | Leading and trailing spaces trimmed; spaces between words kept |
| Number-like text values | Normalized, so 14.50 can come back as 14.5 |
The tool parses your XML and rebuilds it, so the result is a clean serialization of the document rather than a simple search-and-replace of spaces.
Tips and Common Mistakes
- Keep the original file. Minifying is meant for output, not for your only copy of the source.
- Check whitespace-sensitive content. Whitespace can matter in mixed content (text and tags together) or inside elements marked
xml:space="preserve". Test the minified result where it will be used. - Know what re-serialization does. Comments are dropped, CDATA becomes escaped text, and number-like values can be normalized, so keep the source if any of that matters for your data.
- Fix Parse Errors at the source. The usual causes are unclosed tags, mismatched tag names, attribute values without quotes, and unescaped
&or<characters. - Escape special characters. Use
&,<,>,", and'inside text and attribute values. - Test before replacing. If another system reads the XML, send it the minified version in a test environment before you replace the original.
- Combine with server compression. Gzip or Brotli on your server works on top of minification and saves more on larger files.
Common Use Cases
- SOAP and XML API requests: shorter payloads that are easier to paste into tools and logs.
- Configuration files: compact copies for storage or deployment.
- Sitemaps and feeds: smaller RSS, Atom, or sitemap files.
- Test fixtures and code strings: XML on a single line is easier to embed in code.
- Data exchange: smaller messages between systems.
Frequently Asked Questions
How do I minify XML online?
Paste your XML into the input box, click Minify XML, then copy the result or download it as an .xml file. The Original, Minified, and Saved values show how much space you saved.
Will minifying XML change my data?
Minifying removes indentation, line breaks, and whitespace between tags. Elements, attributes, namespaces, and their order keep their names and order. The document is parsed and rebuilt, so comments are dropped, CDATA becomes escaped text, and number-like text such as 14.50 may be normalized to 14.5. Test the result first if exact text matters.
How do I minify XML for a SOAP request?
Paste the full SOAP envelope and click Minify XML. Namespaces, prefixes, and attributes stay as written, and only the whitespace between tags is removed. See the SOAP example above.
How do I convert XML to a single line?
Use Minify XML. It removes the line breaks and indentation between tags, so a typical XML document ends up on one line.
Can I turn minified XML back into readable XML?
Yes. Paste the minified XML and click Beautify to get an indented, one-element-per-line layout. It will not restore your original spacing, only a clean readable format.
Why do I get a Parse Error?
The XML is not well-formed. Common causes are an unclosed tag, mismatched opening and closing tags, an attribute value without quotes, or an unescaped & or < in text. Fix the error and run it again.
How much smaller will my XML be?
It depends on the file. In the examples above, a small catalog saves 17.0% and a short SOAP request saves 10.3%. Larger files with deep indentation often save more. The size comparison shows the exact numbers for your input.
Is my XML uploaded to a server?
No. The XML is processed locally in your browser, and nothing is uploaded or stored.