Skip to content

XML Minifier

Compress an XML document by removing the whitespace between elements and, optionally, comments.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is XML Minifier?

Pretty-printed XML carries a lot of whitespace that only exists for humans. Minifying removes the indentation and line breaks between elements so that the document is smaller and fits on one line, for example when it must be stored in a database field, embedded in a string or sent in a size-limited request.

The tool checks that the XML is well-formed, then removes whitespace-only text between elements and (by default) comments. Text inside elements, CDATA sections, attributes, the XML declaration and mixed content such as <p>Hi <i>you</i></p> are preserved, and a report shows the size before and after.

How does it work?

  1. Paste your XML in the input box.
  2. Leave “Keep comments” off to strip them, or turn it on to preserve them.
  3. Read the size report and copy the one-line result.
  4. Download minified.xml if you need a file.

Common use cases

  • Reducing the size of XML stored in a database column or a cache.
  • Embedding an XML snippet in a JSON string or an HTTP header value.
  • Shrinking SVG-like or configuration XML before shipping it.
  • Removing developer comments from an XML file before publishing.

Examples

Try this input in the tool above:

Input
<?xml version="1.0"?>
<config>
  <!-- server settings -->
  <server host="localhost" port="8080">
    <name>Main</name>
    <tags>
      <tag>a</tag>
      <tag>b</tag>
    </tags>
  </server>
</config>
Output
<?xml version="1.0"?><config><server host="localhost" port="8080"><name>Main</name><tags><tag>a</tag><tag>b</tag></tags></server></config>

Privacy

XML Minifier runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Whitespace inside text content is preserved, so minified output is not always the absolute smallest. Documents that rely on xml:space="preserve" should be checked after minification.

Frequently asked questions

Can minifying change the meaning of my XML?

For data-oriented XML no: only formatting whitespace between elements is removed. For document-oriented XML with mixed content, text and inline elements are preserved exactly.

Are comments removed?

Yes by default, because comments are not data. Enable “Keep comments” to preserve them.

Does it work with namespaces and CDATA?

Yes. Prefixes, xmlns attributes and CDATA sections are kept verbatim.

More tools in JSON & Data →