Minify XML

Paste XML and press Minify to strip whitespace between tags, usually down to one line. Text, attributes, comments, CDATA and the XML declaration stay as written. Mixed content is left alone. Well-formedness is checked first, so a broken document is rejected with line and column. Nothing is uploaded.

Input
Output
Well-formed XML9 lines261 BValidated on this device

Runs in this tab · nothing is uploaded · Verify in 10 seconds →

What this does

Minify XML collapses insignificant whitespace between tags into a compact document, usually one line, without touching text content, attributes, comments, CDATA or the XML declaration. Press Minify below; the sample is already compacted so you can see the result.

Only inter-tag whitespace is removed. A pretty-printed catalog with two-space indent typically shrinks 15 to 35 percent; already-compact SOAP bodies barely change. Mixed content and xml:space="preserve" regions are left alone, so a poem inside <pre> does not lose its line breaks.

When it goes wrong

If Minify is disabled and the status bar is red, the document is not well-formed: fix the reported line and column first. If a downstream system then rejects the compact form, it was depending on ignorable whitespace, which XML treats as insignificant between elements.

When to use this

Minify before embedding XML in a log line, a message queue payload or a unit-test fixture, and after you have validated the document.

This page is a focused view of theXML Formatter, Validator & Pretty Print, which has the full set of options.

Frequently asked questions

Does minifying change my data?

Only whitespace between tags. Text, attributes, comments and CDATA stay byte-for-byte.

How do I minify XML?

Paste it and press Minify. Invalid XML is rejected with the first error's line and column.

Will comments and CDATA survive?

Yes. The minifier is a tokenizer that only removes whitespace between tags.

Is the XML uploaded?

No. Minifying runs in this tab.

What about mixed content?

Whitespace inside mixed content (text and child elements in the same parent) is left alone.

Can I pretty-print it back?

Yes. Press Format on this page, or open the full XML Formatter for indent options.