Minify XML

Minify XML while preserving text-node whitespace and escaped values.

freeworks offlinenothing uploaded
ToolXML Minifier
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

Inter-element whitespace and comments are removed where XML permits, while text nodes, attributes, and entity references remain escaped. The result is compact XML serialization.

  • Whitespace between elements is usually formatting-only.
  • Text-node whitespace remains because applications may treat it as data.

Worked example

Minify XML
Remove whitespace and comments from XML
Input
											<root>
  <!-- Config -->
  <item>
    <name>Test</name>
  </item>
</root>
										
Output
												<root><item><name>Test</name></item></root>
											

When to use this

SOAP payloads, SVG bundles, and XML fixture snapshots use minification.

Edge cases

  • Mixed-content paragraph whitespace is significant.
  • CDATA contains markup-looking characters without creating elements.
  • Double hyphens in comments are invalid XML.

References