XML Minifier

Compact XML to a single line by removing whitespace between tags and, optionally, comments. The document is checked for well-formedness first.

Loading tool…

About the XML Minifier

The minifier checks the document with the browser's XML parser, then walks its tokens: whitespace-only text between tags is removed, runs of whitespace inside tags are collapsed (<dependency scope = "test" > → <dependency scope="test">), and comments are dropped when Remove comments is ticked. CDATA sections, processing instructions and attribute values are left byte-for-byte intact.

Collapse whitespace in text trims text nodes and reduces internal runs of spaces and newlines to a single space. That is right for data-oriented XML — configuration, SOAP envelopes, sitemaps, RSS feeds, SVG — but untick it for documents where whitespace in text is meaningful, such as elements with xml:space="preserve" or mixed-content prose.

The status line shows the size before and after and the bytes saved. Heavily indented files often shrink by 20–40%. If you minify XML for transport, remember that gzip already removes most of the cost of indentation; minification matters more for storage, embedding XML in strings, or systems that limit message size. The work happens entirely in your browser.

How to use it

  1. Paste XML or open a file.
  2. Choose whether to remove comments and collapse text whitespace.
  3. Fix any well-formedness error that is reported.
  4. Copy the result or download document.min.xml.

Frequently asked questions

Does minifying XML change the data?
Removing whitespace between elements does not change the data for most XML applications. Collapsing whitespace inside text nodes can, so turn that option off for whitespace-sensitive documents.
Are CDATA sections preserved?
Yes. CDATA content is copied exactly, including line breaks and spaces.
Can I minify SVG with this?
Yes, SVG is XML. For extra savings such as shortening path data and removing editor metadata, use a dedicated optimizer like SVGO.

Related tools