XML Formatter
Format XML with proper indentation, or minify it. Checks that tags are balanced and preserves CDATA, comments, DOCTYPE and declarations exactly.
Related tools
All Developer tools →This tool runs entirely in your browser. Nothing you enter is sent to our servers, so there is nothing for us to store or see.
About the XML Formatter
Paste XML and get it back properly indented, or minified down to a single line. Works on anything XML-shaped: an RSS feed, a sitemap, a SOAP envelope, a Maven POM, an Android layout, a SVG file.
Everything that carries meaning is preserved exactly as written. The XML declaration and any DOCTYPE stay at the top, processing instructions keep their position, comments are kept unless you ask for them to be dropped, and CDATA sections come through untouched — including the markup inside them, which a naive formatter cheerfully re-indents and thereby corrupts. An element written <a/> stays that way rather than being rewritten as <a></a>, because to some readers those are different documents and a formatter has no business making that call.
Before formatting, the document is checked for well-formedness: every tag balanced, closed in the right order, and exactly one root element. A mismatch is reported with the line the tag was opened on and the line where it went wrong, which is the pair of numbers you actually need. This is a well-formedness check, not a schema check — it does not validate against a DTD or XSD, and does not pretend to.
How to use the XML Formatter
-
Paste your XML
Into the left box, or drop an .xml, .svg or .rss file onto it. Formatting starts as soon as you stop typing.
-
Choose the indentation
Two spaces, four spaces or tabs. Choose Minify instead to strip every formatting character and put the document on one line.
-
Fix anything unbalanced
If a tag is closed in the wrong order or never closed at all, the message names both lines — where it opened and where the problem showed up.
-
Copy or download
The formatted document appears on the right. Copy it to your clipboard or download it as an .xml file.
Frequently asked questions
Does this validate my XML against a schema?
No. It checks well-formedness — that tags are balanced and correctly nested, that there is exactly one root element, and that comments, CDATA sections and the DOCTYPE are properly closed. Validating against a DTD or XSD is a different job requiring the schema itself, and this tool does not claim to do it.
Will formatting change what my XML means?
Only the whitespace between elements changes. Text content, attributes, attribute quoting, CDATA and comments are all preserved character for character. Be aware that in XML, whitespace inside an element is technically significant, so a document relying on indentation as data — rare, but it happens in some configuration formats — should not be reformatted.
Why did my CDATA section survive but a comment inside it disappear?
A CDATA section is copied verbatim, so nothing inside it is examined or altered — that is the whole purpose of CDATA. What looks like a comment inside one is just text, and the drop-comments option never touches it, because to the formatter it is not a comment at all.
Can it handle a large file?
Yes. The formatter is a single linear pass over the document, so a file with tens of thousands of elements formats in well under a second. The practical ceiling is how much text your browser will hold in a textarea, not the formatting.
Is my XML uploaded anywhere?
No. Parsing and formatting both happen in your browser and nothing is transmitted or stored, which makes this safe for a SOAP payload, a configuration file or an export containing personal data.