Skip to content
DevToolKit

XML Minifier

Compress XML by removing comments, collapsing whitespace, and merging empty tags while preserving CDATA and text content.

XML Utility

XML Minifier

Configuration

Remove CommentsStrip <!-- ... --> comments
Collapse WhitespaceRemove whitespace between tags
Collapse Empty Tags<tag></tag> → <tag/>
Safe Minification

CDATA sections, text node content, and attribute values are never modified — only whitespace between tags and comments are touched.

XML Input
Minified Output
Was this tool helpful?

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.

  1. Paste XML: Enter your XML document into the input panel. Supports XML declarations, processing instructions, CDATA sections, namespaces, and deeply nested structures.
  2. Configure options: Toggle comment removal, whitespace collapsing, and empty tag collapsing independently to control exactly what gets minified.
  3. Review stats: The statistics panel shows original size, minified size, bytes saved, and reduction percentage updated in real time as you type.
  4. 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.

FAQ

Does the XML minifier modify content inside CDATA sections?
No. CDATA sections are treated as opaque blocks and passed through completely untouched. The tokenizer recognizes <![CDATA[...]]> boundaries and preserves everything between them, including whitespace, line breaks, and special characters. This ensures embedded code, pre-formatted text, or raw data within CDATA remains exactly as authored.
What does 'Collapse Empty Tags' do?
When enabled, empty element pairs like <tag></tag> are converted to the self-closing form <tag/>. This applies to elements with attributes too — <item id="5"></item> becomes <item id="5"/>. Both forms are semantically identical in XML, but the self-closing form saves bytes and is more concise.
Will minification break my XML document?
No. The minifier uses a tokenizer-based approach that only modifies whitespace between tags and optionally removes comments. It never alters tag names, attribute values, text node content, CDATA sections, or processing instructions. The output is a well-formed XML document semantically identical to the input.
When should I minify XML?
XML minification is useful when transmitting XML over APIs or network connections where payload size matters, storing XML in databases or configuration systems with size constraints, embedding XML in log entries where line breaks disrupt log parsers, and reducing file size for XML-based formats like SVG, SOAP envelopes, or RSS feeds.