Skip to content
Browser tool Runs locally

XML Minifier

Compact XML markup while preserving text whitespace. Runs locally.

XML input
0 chars
Minified XML
Minified XML will appear here.

How to use the XML Minifier

Paste XML, choose Minify XML, then review the result before copying or downloading it. A parse error stops the transformation; correct the reported tag, entity or attribute problem first. Keep the original when changing a file used by another system.

A compact markup example

Input <r a='1' /> becomes <r a="1"/>. Tag spacing and quotes are normalized. Existing text is retained: <p><b>Hello</b> <b>world</b></p> keeps the space between the two words. Removing that space would change the document.

Why indentation is retained

XML does not identify a whitespace-only text node as disposable merely because it sits between tags. Without a schema or application content model, this tool cannot safely decide that indentation has no meaning. It therefore preserves those nodes, even when the result remains several lines long or is no smaller than the input.

Preserved content and browser limits

Namespace declarations and prefixes, CDATA, comments, processing instructions, the XML declaration and document type declaration are retained. Browser parsing can normalize XML line endings and expand supported internal entities; the output is a serialized document, not a byte-for-byte copy. External schemas are not used for validation. For signed XML, retain the original and use the signing system’s specified canonicalization method.

Which tool should I use?

Use this Minifier when you only need compact markup. XML Formatter & Validator includes Minify and Validate controls as well as formatting. Use XML Diff to compare parsed structure, attributes and text spacing. Add indentation only when your application permits extra whitespace; transport compression such as gzip addresses bandwidth separately.

Frequently asked questions

What does this XML minifier change?
It serializes parsed markup compactly, normalizing tag spacing and attribute quotes. It retains all text nodes, including indentation and spaces between child elements, because their meaning cannot be inferred without a content model.
Why does the output still contain newlines?
Newlines between elements are text nodes. Removing them can change document data, so this tool preserves them. Markup already serialized compactly may not shrink, and normalized quotes or entities can make output larger.
Does minification produce canonical XML?
No. This is ordinary serialization, not XML Canonicalization (C14N). Do not use it to create signature bytes or assume semantically equivalent documents have identical hashes.
What happens to mixed content and xml:space?
Text spacing is retained throughout the document, including xml:space="preserve" and nested xml:space="default" elements. CDATA, comments, processing instructions and namespace declarations are retained.
Is this compression or schema validation?
No. Gzip compresses bytes for storage or transport. This tool checks browser-native XML well-formedness; it does not validate a DTD or XSD content model.

Related tools