XML Minifier
XML Minifier strips indentation and whitespace-only nodes from valid XML, collapsing a formatted document onto one line. Comments, CDATA, the DOCTYPE, namespaces and text content are kept as they are. Paste or load a file, minify, then copy the result or download it as minify-output.xml.
사용법 XML Minifier
출력
내용 읽기
What this XML minifier actually removes
Paste a formatted XML document and the tool parses it, then writes it back without the indentation. Sibling elements end up on the same line, the ASCII whitespace that only existed to make the file readable is dropped, and the result is a compact document that carries the same data.
"Minify" here has a narrow meaning. The tool removes whitespace-only nodes between elements and disables pretty printing. It does not strip comments, does not rewrite text content, does not shorten element or attribute names, and does not remove CDATA. If you need those things, this is not the tool for that job.
Before and after
Input:
<root>
<!-- keep -->
<a> x y </a>
<b><![CDATA[ raw <tag> ]]></b>
<c attr="one two" />
<d></d>
</root>
Output:
<?xml version="1.0"?>
<root><!-- keep --><a> x y </a><b><![CDATA[ raw <tag> ]]></b><c attr="one two"/><d/></root>
The comment survived, the CDATA block survived, and the spaces inside the text element survived exactly as typed. Only the line breaks and indentation between elements disappeared.
What is removed and what is kept
| Item | Minify behaviour |
|---|---|
| Indentation and line breaks between elements | Removed |
| Whitespace-only text nodes | Removed, including spaces between inline child elements |
| Comments | Kept |
| CDATA sections | Kept, contents untouched |
| Text content whitespace | Kept exactly |
| DOCTYPE | Kept |
| XML declaration | Kept, or added if missing |
| Empty element pairs | Rewritten as self-closing tags |
| Attribute values | Kept, with newlines normalised to spaces per the XML spec |
| Namespaces and prefixes | Kept |
The mixed-content trap
Whitespace between elements is usually insignificant, which is why removing it is safe for data documents. It becomes significant in mixed content, where text and inline elements share a parent. The parser treats an element that contains only child elements as element-only content, so whitespace-only nodes there are discarded:
<p><b>a</b> <b>b</b></p>
becomes
<p><b>a</b><b>b</b></p>
which renders as "ab" rather than "a b". If a sentence contains inline markup separated by spaces, or if you are minifying XHTML, SVG text or any document where layout depends on inter-element whitespace, check the output before publishing it. This is the one behaviour that can change meaning rather than just appearance.
What it does not do
- It does not remove comments. A comment-heavy file stays comment-heavy.
- It does not collapse spaces inside text. Runs of spaces in a text node are preserved.
- It does not shorten names. No element or attribute is renamed.
- It does not drop namespaces or unused declarations.
- It does not validate against a schema or DTD, and it does not check that the data makes sense.
- It does not repair invalid XML. A missing close tag or a bare ampersand fails the parse and produces no output.
- It does not guarantee the smallest possible file. A dedicated minifier that also strips comments will usually do better.
How to use the page
- Make sure the language selector says XML and the mode is Minify.
- Paste the document into the Manual tab, or fetch a text file through the From URL tab.
- Press Minify. The compact document appears in the output panel, or an error appears if the input is not well-formed.
- Compare the output character count with the input count in the footer badges. On a typically indented file, most of the saving comes from indentation, not from content.
- Copy the result or download it as
minify-output.xml. - Run a validator or your application's parser over the result once, especially if the source had mixed content.
Where it is useful
- Payload size. Removing indentation from a generated XML response reduces bytes, though a compression layer usually achieves more.
- Logs and trace files. A pretty-printed request body becomes a single line that is easier to paste into a log entry or a chat message.
- Configuration snapshots. Compact XML is easier to store in a database column or compare as one string.
- Diff noise. When two files differ only in indentation, minifying both makes the real difference visible.
- Embedding XML. A compact document is easier to place inside a JSON string or an environment variable.
It is a poor fit for XHTML pages, SVG artwork with text, documentation in XML, and anything that will be read by a person afterwards. Readability is the thing minification removes.
How much smaller does the output get?
The saving comes almost entirely from indentation, so it depends on how deeply the source was indented. In a test with a 20-item product catalog written with two and four space indentation, the input measured 2,344 characters and the minified output 1,946 characters, a reduction of about 17 percent. The output also gained the XML declaration, which offsets a few bytes.
A document with one tab per level and dozens of nested elements saves more. A file that was already written on a single line saves almost nothing, because only the declaration, self-closing tags and attribute normalisation change. If bytes matter enough to measure, compare the input and output counters in the footer before deciding that minification is worth the loss of readability.
What it does to already-compact XML
Running the minifier on a file that has no indentation still produces changes: the XML declaration is ensured, empty element pairs become self-closing tags, and attribute values are normalised. Comments and CDATA remain. If your input is already one line, expect the output to look nearly identical apart from those details, and expect the character count to move slightly rather than drop.
Limits
Input is capped at 200,000 characters per request. The document is parsed into memory on the server, so a deeply nested file near the limit can be slower than its size suggests. The tool handles one document per request, does not stream, does not batch files and does not preserve the original line endings because it rewrites the whole serialisation. A file with multiple root elements is invalid and is rejected.
Privacy
Your XML is sent to the server. Remove tokens, passwords, personal data and internal hostnames before pasting, particularly from SOAP envelopes, SSO assertions and configuration exports. The page does not keep a history, but the document does leave the browser during processing.
Common mistakes
- Expecting comments to disappear. They are kept; this is not a full compressor.
- Minifying XHTML with inline spacing. Whitespace between inline elements can be removed, changing the rendered text.
- Minifying a signed document. Any byte change invalidates the signature.
- Pasting HTML. Optional end tags and bare ampersands are not valid XML and fail the parse.
- Assuming the output is airtight. Validate it once before replacing a production file.
- Using it for archival. Keep the readable original; the compact version is for transport.
Frequently Asked Questions
자주 묻는 질문
댓글 (0)
발생한 문제를 자세히 설명해 주시면, 저희가 이를 조사하고 도구를 개선할 수 있습니다.