XML Minifier

Minify XML by removing comments and inter-element whitespace.

  • Runs locally in your browser
  • No upload required

Try it

Paste XML. Attributes, CDATA and text are preserved; malformed XML is rejected.

Minified XML
<a><b>1</b><b>2</b></a>
Size
30 → 23 characters (7 saved)

Supported formats

Input
text, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Reduced 30 to 23 characters of XML.

How it works

  • Removed XML comments.
  • Collapsed whitespace between element tags.
  • Preserved element names, attributes, CDATA and text content.
  • Rejected malformed markup before transforming it.
  • Whitespace between two elements is treated as formatting and removed; whitespace inside text content is collapsed to one space.
  • When remove-comments is off, comments are preserved verbatim.
  • Output is 23 character(s); minifying it again changes nothing.

Methodology

  1. Tokenise the markup with the shared quote-aware scanner so `>` inside an attribute cannot end a tag.
  2. Check well-formedness with an element stack and fail closed on a mismatch.
  3. Emit tags with normalised whitespace, drop inter-element text nodes and optionally remove comments.

Usage

  1. Paste or type an XML document.
  2. Choose whether to remove comments.
  3. Run the minifier and copy the compact result.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Elements collapsed

jsonSelect to copy
{
  "text": "<a>\n  <b>1</b>\n  <b>2</b>\n</a>",
  "removeComments": true
}

Comment removed

jsonSelect to copy
{
  "text": "<!-- note --><a>x</a>",
  "removeComments": true
}

CDATA preserved

jsonSelect to copy
{
  "text": "<a><![CDATA[  raw  ]]></a>",
  "removeComments": true
}

Limitations

Why minify XML

Whitespace between elements and comments are often the largest avoidable part of a generated XML document. Removing them shrinks the payload without changing the data.

Because the tool verifies well-formedness first, a malformed document is reported rather than silently narrowed.

Frequently asked questions

Does minifying change my XML data?
No. Element names, attributes, CDATA and text are preserved; only comments (when selected) and inter-element whitespace are removed.
What happens to malformed XML?
A mismatched or unclosed tag is rejected with a line and column instead of being silently transformed.
Is my XML uploaded?
No. All processing happens in your browser and nothing is sent anywhere.

Sources

  1. Extensible Markup Language (XML) 1.0 — W3C
  2. MDN Web Docs — XML introduction — MDN