Skip to content

XML Minifier

Minify XML by stripping the indentation between tags and, unless you keep them, the comments.

Input · XML

Valid XML

Well-formed XML 1.0

  • root <urlset>
  • 7 elements
  • depth 3
Valid XMLroot <urlset> · 7 elements · depth 3Runs in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to minify XML

  1. Paste the XML or drop the file onto the tool.
  2. Press Minify (Ctrl + Enter). Turn on Keep comments to keep notes such as licence headers.
  3. Format or the XML formatter restores the indentation when you need to read it.

Example: an icon from a design tool

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by the icon exporter -->
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  <title>Bell</title>
  <!-- outline -->
  <path d="M18 16v-5a6 6 0 0 0-12 0v5l-2 2h16z"></path>
  <circle cx="12" cy="20" r="2" />
</svg>

Minified, 301 characters become 224 (279 with Keep comments):

<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>Bell</title><path d="M18 16v-5a6 6 0 0 0-12 0v5l-2 2h16z"/><circle cx="12" cy="20" r="2"/></svg>

Both comments are gone, <path ...></path> became <path .../>, and the space before /> in <circle> was dropped.

What stays exactly as written

  • Text inside elements, including spaces and line breaks.
  • Mixed content: in <p>Hi <b>there</b>, Sam</p> the spaces around <b> belong to the sentence, so the element is left alone.
  • Attribute values and quotes, CDATA, the XML declaration, the DOCTYPE and processing instructions.

It is not an SVG optimizer: path data, number precision and elements such as <title> are kept.

Where minified XML helps

Inline SVG in HTML or CSS, XML in a database column, and XML inside a JSON field. For the last, minify first, then run it through JSON escape. For JSON documents, use JSON minify.

Questions

Why did <a></a> turn into <a/>?

Both mean the same in XML and the short form saves bytes, so empty elements are always written self-closing.

Can it minify XML that has errors?

No, it has to parse the document first. The Report tab shows the line and column, and the XML validator explains each message.

Is minifying worth it if the server already uses gzip?

Less so: gzip compresses repeated indentation well, so the gain after compression is smaller than the character count suggests. It pays off where XML is stored or embedded uncompressed.

Related tools

Esc