How to use the XML minifier
- Paste your document into the XML box. A small product feed is there as a sample.
- Keep Remove comments ticked to drop
<!-- … -->comments, or untick it to keep them. - The Minified XML appears below with Saved, Original and Minified sizes.
- Copy the result or download it as
minified.xml.
What it does and when to use it
Pretty-printed XML carries a lot of indentation that no program reads. Minifying it makes API payloads, SOAP requests, sitemaps, config blobs and feed files smaller, and puts a document on one line so it fits in a log entry, a test fixture or a string constant.
To read a minified file again, use the XML formatter. To move between formats, try XML to JSON or JSON to XML. The SQL minifier does a similar clean-up for database queries.
How it works
First, fast-xml-parser’s validator checks that every tag is closed and nested correctly. If not, you see the line, column and reason, and nothing is minified.
Then the tool’s own tokenizer splits the document into tags, text, comments, CDATA and declarations, and builds the element tree. While writing it out again it:
- drops text nodes that are only whitespace,
- keeps every text node with visible characters exactly as written,
- rewrites each start tag with single spaces between attributes and no space before
>or/>, - removes comments when the box is ticked,
- keeps all whitespace inside an
xml:space="preserve"element.
All of this runs in your browser; the XML is not uploaded.
Worked examples
These are the tool’s own outputs.
The sample feed. With comments removed, the 136-byte sample becomes 96 bytes, Saved: 29.4%:
<?xml version="1.0"?><feed><item id="1"><name>Desk lamp</name><price>24.99</price></item></feed>
With Remove comments unticked, <!-- product feed --> stays and the saving drops to 14%.
Text with its own line breaks. This note has a padded start tag and a multi-line body:
<note>
<to lang="en" >Asha</to>
<body>
Meet at 10.
</body>
<logo src="a.png" />
</note>
The result is <to lang="en"> and <logo src="a.png"/> on one line, but the body keeps its newlines because they are part of its text.
Badly nested tags. <a><b></a> returns “XML is not well-formed at line 1, column 7: Expected closing tag ‘b’…”.
Limits and tips
- Whitespace inside values stays. The tool cannot know whether spaces in your text matter, so it never trims them.
- No renaming or shortening. Namespace prefixes, attribute quotes and entity references are left as they are.
- Compression helps more. Gzip on the server usually saves far more than minifying; the two work together.
- Keep the readable original for editing, and minify a copy.
Frequently asked questions
Can minifying change what my XML means?
Why is there still a line break in my output?
Are CDATA sections and the XML declaration kept?
Does it check that the XML is valid?
How much will my file shrink?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.