XML minifier

Good for shrinking config files and messages before sending them through an API or storing them.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter xml text and remove comments.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

The document is parsed to confirm it is well-formed, then whitespace-only text between tags is removed, plus comments if selected. Saving = (original length - new length) / original length x 100, lengths in characters.

Example

Inputs: Remove comments = yes. Result: Minified XML: <root><a x="1">t</a><b/></root>; Characters before: 57; Characters after: 31.

<root>
  <!-- note -->
  <a x="1">t</a>
  <b></b>
</root>
<root><a x="1">t</a><b/></root>

Limits and caveats

  • A lone space between two tags in mixed content, as in <b>a</b> <i>b</i>, is removed as an empty node.
  • Text inside elements is not changed, so spaces within it stay.

Questions about this tool

Is the XML still valid after minifying?

Yes, structure, attributes and text are the same, only whitespace between tags and comments are removed.

How is the saving worked out?

Output length is subtracted from the original, divided by the original and multiplied by 100, so 57 to 31 characters is 45.6%.

Is the <?xml ?> declaration kept?

Yes, it stays at the start because it states the version and encoding.