XML Minifier

Shorten an XML document.

Use this tool

Result

The result appears in this panel after you run the tool.

About this tool

Comments and extra space between tags are removed.

A document that is not well formed can still be processed as text.

How to use it

  1. Open this page and provide the input it asks for.
  2. Set the options that are visible, then use Minify XML.
  3. Read the result in the panel. Copy it or download it when a file is offered. The input stays in this browser.

Limitations

Element text squeezed without a well-formedness test

Delimiters are removed by pattern, not by a parser

The same family of substitutions used for HTML markup is applied to XML text, and the result is labeled XML. Each comment, from its opening delimiter to its closing delimiter, is discarded. Whitespace sitting between one tag’s end and the next tag’s start is removed so the tags touch. Any remaining run of two or more whitespace characters becomes a single space. Ends are trimmed. A blank box is rejected before those substitutions run.

No XML parser is asked whether the document is well formed. A missing end tag, a mismatched name, and an illegal character are not reported. The formatter is the page that uses the browser parser and refuses a document the parser rejects. This minifier can shorten a broken file and hand the broken file back. Attributes, processing instructions, and the declaration are whatever characters remain after the substitutions. They are not interpreted. A declaration’s internal spaces may shrink.

Significant spaces and comments are the losses

Mixed content that used two spaces between words loses one. A comment that held a processing note is gone and cannot be rebuilt from the short form. A CDATA section is not specially recognized, so the substitutions can touch it. If your document uses whitespace inside a text node as data, compare before you replace the original. The XML-to-JSON converter is a different tool: it parses, may turn digit text into numbers, and names attributes with a prefix. This page does none of that. It only shortens text.

Indent belongs on the formatter

There is no two-space or four-space control here. Adding indent would fight the purpose. When you need to read the document, format it. When you need fewer characters between tags and you accept deleted comments, minify it. Neither step validates against an XSD, and neither step repairs a tag.

Privacy

Your input is processed in your browser and is not uploaded to UtilChain. File names, text, and results are not sent to analytics.