XML formatter & minifier
Pretty-print or minify XML with 2/4-space or tab indentation, one attribute per line and optional comment removal; keeps the XML declaration, DOCTYPE, comments and CDATA, reports exact line/column on errors and counts nodes and attributes.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Output
Enter XML to see the result
Statistics
Enter XML to see the result
What this tool does
- Paste a single-line API response, log line or config file and get readable indentation instantly, then drill into the structure instead of adding line breaks by hand.
- Shrink a payload for shipping: minify removes whitespace between tags and optionally comments, while the byte counters show the size before and after.
- Debug "tag not closed" failures — the parser points at the line, column and reason (mismatched tag, duplicate attribute, multiple roots) instead of leaving you to count brackets.
- Check the shape of a document before committing it: element, attribute, comment, CDATA and max-depth counts are shown together.
Example
Input
<user id="1"><name>Ada</name><tags><tag>go</tag><tag>xml</tag></tags></user>
Output
<user id="1">
<name>Ada</name>
<tags>
<tag>go</tag>
<tag>xml</tag>
</tags>
</user>Result with the default Format mode and 2-space indent. Switching to Minify returns the original single line; the stats panel reports 5 elements, 1 attribute and max depth 3.
Frequently asked questions
Does formatting change my document?
It never changes the data, only the layout: whitespace-only text nodes between tags are dropped, while elements whose children are pure text or CDATA (such as <name>Ada</name>) stay on one line. Spaces inside attribute values, the original quote style and entity references are preserved.
Why does it complain about "multiple roots"?
XML allows exactly one root element, so two sibling top-level tags (or several fragments) must be wrapped in a <root> element. The parser also checks tag matching, duplicate attributes, valid names and unterminated comments or CDATA, and reports the line and column of the problem.
Are DOCTYPE, comments and CDATA supported?
Yes. DOCTYPE declarations (including an internal [ ] subset), processing instructions such as <?xml ... ?>, comments and CDATA sections all parse and round-trip unchanged, and minify can optionally strip comments for you.
Are entity references expanded?
No. Entities like &, < and A are left exactly as written, because formatting should only touch layout and never rewrite text semantics. Use the XML to JSON tool when you need them decoded.
Does it handle large files?
Parsing uses a hand-written tokenizer with no DOM and no third-party library, so a few hundred thousand characters are usually fine. The formatted output is still one big string, so for very large files trim to the relevant fragment first. Everything runs locally in your browser and is never uploaded.
Keywords:xmlxml 格式化xml formatter美化压缩minifypretty printcdataxml 在线格式化