XML Minifier
Compress XML by removing comments, collapsing whitespace, and merging empty tags while preserving CDATA and text content.
How to Use
Compress XML documents by removing comments, collapsing whitespace between tags, and converting empty element pairs to self-closing form. CDATA sections and text node content are always preserved.
- Paste XML: Enter your XML document into the input panel. Supports XML declarations, processing instructions, CDATA sections, namespaces, and deeply nested structures.
- Configure options: Toggle comment removal, whitespace collapsing, and empty tag collapsing independently to control exactly what gets minified.
- Review stats: The statistics panel shows original size, minified size, bytes saved, and reduction percentage updated in real time as you type.
- Copy result: Click the copy button to grab the minified XML for use in your API payloads, configuration files, or embedded strings.
About This Tool
Tokenizer-Based XML Minification
This tool uses a custom tokenizer that splits XML into discrete segments: XML declarations (<?xml ...?>), processing instructions (<?target ...?>), CDATA sections (<![CDATA[...]]>), comments (<!-- ... -->), tags (opening, closing, and self-closing), text nodes, and inter-tag whitespace. Only whitespace tokens and comment tokens are candidates for removal. CDATA blocks, text node content, and attribute values inside quotes pass through completely untouched. This guarantees the minified output is a semantically identical XML document — no data loss, no structural changes.
Empty Tag Collapsing
In XML, <tag></tag> and <tag/> are semantically equivalent — both represent an element with no content. The empty tag collapsing option converts the verbose two-tag form into the concise self-closing form, saving 3+ bytes per empty element. This is particularly effective for configuration files with boolean-like empty elements, SVG documents with empty <path> or <rect> elements, and SOAP envelopes with placeholder tags. Elements with attributes are handled correctly: <item id="5"></item> becomes <item id="5"/>.
CDATA Preservation
CDATA sections (<![CDATA[...]]>) exist to embed raw text that should not be parsed as XML markup. They commonly contain embedded JavaScript, SQL queries, HTML fragments, or pre-formatted text with special characters like <, >, and &. This minifier treats every CDATA block as an opaque token — the content between <![CDATA[ and ]]> is never inspected or modified, preserving indentation, line breaks, and any characters that would otherwise need XML entity escaping.
Why Use This Tool
Private, Client-Side XML Processing
XML documents often contain sensitive configuration data — database credentials, API endpoints, encryption keys, and internal service URLs. This tool processes everything entirely in your browser using a JavaScript tokenizer. No XML is ever transmitted to any server, making it safe for production configurations, SOAP messages with authentication headers, and any XML containing proprietary schema definitions.
Typical XML configuration files with comments and generous formatting achieve 40-60% size reduction when minified. SVG files with empty elements and verbose whitespace often see 25-45% savings. The real-time statistics panel quantifies these savings instantly as you paste your document.