XML Formatter
Format and minify XML documents with proper indentation.
Last updated: August 2026
Was this tool helpful?
Reading and shrinking XML
An XML formatter does two opposite jobs. Pretty-printing adds indentation and line breaks so nested elements are readable. Minifying strips that whitespace back out to make the document as small as possible for transmission. Neither changes the data, only the whitespace between tags.
Example
Minified:
<order id="7"><item>A1</item><item>B2</item></order>Pretty-printed:
<order id="7">
<item>A1</item>
<item>B2</item>
</order>The whitespace-is-significant trap
This is the catch that bites people. In XML, whitespace inside an element can be meaningful text content. If an element holds mixed content, text and child elements together, reformatting may insert or remove spaces that are actually part of the data. For data-only XML (configs, API payloads) pretty-printing is safe; for document-style XML with prose, it can subtly corrupt content.
Keeping it well-formed
A formatter must parse the input first, so it will reject XML that is not well-formed: an unclosed tag, mismatched nesting, or an unescaped & that should be &. That makes it a quick validity check as a side effect. Entities and CDATA sections are preserved rather than expanded, so your escaped characters stay escaped.
FAQ
Why did my formatter refuse the file? It is almost always a well-formedness error, a stray <, an unclosed tag, or a bad entity. Fix the parse error and it will format.
Does minifying ever break XML? It can if whitespace inside mixed content was significant, so minify data-oriented XML freely but be careful with document text.
Can it convert to JSON? Formatting only touches layout. For a structural change, use XML to JSON.