Skip to content
koducathome

XML Minifier

Minify XML by removing the whitespace between tags — text, CDATA and xml:space="preserve" stay exactly as they are — and optionally drop comments.

How to use this tool

Steps for using the XML Formatter.

  1. Minify is selected. Paste XML into Input XML or click Upload file — the minified XML appears as you type.
  2. Comments are kept by default; turn on Remove comments to drop them as well.
  3. Malformed XML is reported with its line and column instead of being minified, so you never ship a broken file.
  4. Copy or download the result. To make it readable again, switch to Format.

Example

Whitespace between tags removed, comment kept

XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- order export -->
<order id="1042">
  <customer>Ada Lovelace</customer>
  <items>
    <item sku="KB-1" qty="1">Keyboard</item>
    <item sku="MS-2" qty="2">Mouse</item>
  </items>
</order>
Minified
<?xml version="1.0" encoding="UTF-8"?><!-- order export --><order id="1042"><customer>Ada Lovelace</customer><items><item sku="KB-1" qty="1">Keyboard</item><item sku="MS-2" qty="2">Mouse</item></items></order>

Common use cases

  • Shrinking SOAP or REST XML payloads before sending or storing them.
  • Embedding XML in JSON strings, environment variables or database columns.
  • Removing comments from configuration before publishing it.
  • Comparing two XML files after reducing both to the same compact form.

What XML minification removes — and what it keeps

Minifying XML removes the line breaks and indentation between tags, which exist only for people reading the file. Parsers ignore that whitespace in most data formats, so the minified file means the same thing in fewer bytes — useful for API payloads, SOAP messages, config shipped inside apps and files stored in databases.

Text inside elements is never touched: <customer>Ada Lovelace</customer> keeps its space. CDATA sections and elements marked xml:space="preserve" are kept exactly as written, because there whitespace is part of the data. The XML declaration and processing instructions stay too.

Comments are kept unless you turn on Remove comments. Dropping them saves more bytes but also removes notes that might matter to the next person — keep them for config files, drop them for payloads.

Before minifying, the input is checked for well-formedness; errors point at the exact line and column. Compression on the wire (gzip or Brotli) already shrinks indentation well, so minifying matters most where XML is stored or embedded rather than served. To read minified XML, use the XML Formatter.

Limitations

  • Whitespace inside mixed content (text with child elements) is kept as written.
  • Minifying doesn't shorten tag or attribute names — the structure stays the same.
  • Very large files are best processed with a command-line tool such as xmllint.

Frequently asked questions

Does minifying change what my XML means?

No. Only whitespace between tags (and comments, if you choose) is removed. Text content, attributes, CDATA and xml:space="preserve" are kept exactly.

Are comments removed?

Only if you turn on Remove comments. By default they stay in the minified output.

How do I un-minify XML?

Switch to Format (the XML Formatter) — it re-indents the same XML with 2 spaces, 4 spaces or tabs.

Is my XML uploaded?

No. Minifying runs entirely in your browser; files never leave your device.