XML Minifier
Remove whitespace and comments from XML.
XML Minifier – Compress XML Online
The XML minifier removes formatting whitespace and comments from XML documents, producing the most compact representation of the same data. Smaller XML is faster to transfer, cheaper to store, and easier to embed in strings, URLs, or database fields.
What it removes
- Indentation and line breaks between elements.
- Whitespace-only text nodes.
- Comments (unless you enable Keep comments).
What it keeps
- The XML declaration and processing instructions.
- Elements, attributes, and attribute order.
- Namespaces and prefixes.
- Text content, including spaces inside text values.
- CDATA sections and the DOCTYPE.
Strict validation
The minifier parses the document with a strict XML parser before writing it out. A missing closing tag, an unquoted attribute, or an unescaped & is reported with the line and column, so you never get a minified file that is subtly broken.
Size savings
After minifying, the savings chips show the original size, the minified size, and the percentage saved. Pretty-printed XML with deep nesting often shrinks by 20–40%, because indentation grows with every level.
Use cases
- Compact SOAP requests and API payloads before sending them.
- Shrink SVG icons and sprites (use the XML Minifier for safe whitespace removal).
- Store XML configuration in a single database column or environment variable.
- Prepare XML for embedding as a string literal with XML Stringify.
Mixed content
If your document mixes text and elements in the same parent (like XHTML paragraphs with <b> tags), whitespace between elements can matter. Check the result for such documents.
Related tools
Pretty-print XML again with the XML Beautifier, validate it with the XML Validator, or convert it with XML to JSON.
Frequently Asked Questions
Does minifying change my XML data?
Only whitespace between elements and comments are removed. Elements, attributes, and text values stay the same.
Can I minify SVG files with it?
Yes. SVG is XML, so whitespace and comments are removed safely. For path-level optimization, use a dedicated SVG optimizer.
Why do I get a parse error?
The minifier requires well-formed XML: closed tags, quoted attributes, one root element, and escaped special characters. The error shows where the problem is.