Minify an XML document

Compact XML by removing comments and presentation indentation while preserving attributes.

freeworks offlinenothing uploaded
ToolXML Minify
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Optional comments are removed, XML is parsed with attributes preserved, and a compact builder serializes the tree without formatting indentation. An XML declaration can be restored and UTF-8 byte sizes are compared.

  • Comment removal and declaration preservation are separate switches.
  • Compact output removes presentation whitespace rather than elements.

Worked example

Minify indented XML with comments
Remove whitespace, indentation, and comments from a formatted XML document to reduce size by 24%
Input
											<project>
  <modelVersion>4.0.0</modelVersion>
  <!-- Project coordinates -->
  <groupId>com.example</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0.0</version>
</project>
										
Output
												<project><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>my-app</artifactId><version>1.0.0</version></project>
											

When to use this

SOAP payloads, SVG assets, and generated XML configuration are compacted.

Edge cases

  • Whitespace in mixed text content can be normalized by parsing.
  • A comment containing -- is invalid XML and fails.
  • Removing the declaration can discard an explicit encoding marker.

References