XML Formatter
Pretty-print and minify XML with validation.
Recommended tools
Free CDN, DNS, and edge hosting for developers.
Affordable domains and SSL certificates.
Affiliate links — we may earn a commission if you sign up.
About the XML Formatter
The XML Formatter cleans up unstructured markup in both directions: the Format tab pretty-prints any well-formed XML document with two-space indentation, while the Minify tab squeezes the same document into a single line by removing inter-tag whitespace and trimming text nodes. Every conversion is validated first, which is what separates this tool from a naive find-and-replace script. Before anything is formatted, the tool checks basic well-formedness — every opening tag must have a matching close, nesting must be correct, and declarations or processing instructions are treated as leaf nodes. Errors are reported precisely, such as a mismatched tag message that names the expected closing tag, where it was opened, and where the mismatch occurred, so debugging a corrupted payload takes seconds instead of a manual scan. The workspace ships with a compact note document as its sample so you can see both modes immediately, and Clear and Load sample buttons let you reset or restore it. Live stats show input bytes, output bytes, and line count, and the result can be downloaded as formatted.xml or minified.xml. For anyone hand-rolling XML for RSS feeds, sitemaps, or API payloads, this online XML formatter removes the formatting friction.
Examples
<?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body><p>Don't forget me this weekend!</p><p>Bring cake.</p></body></note>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>
<p>Don't forget me this weekend!</p>
<p>Bring cake.</p>
</body>
</note><config> <retry max="3" /> <host>api.fernandeslabs.com</host> </config>
<config><retry max="3" /><host>api.fernandeslabs.com</host></config>
<root><a>one</a><b>two</a></root>
No output — the validation alert reports: Mismatched tag: expected </b> (opened at 16) but found </a> at 22.
How to use
- 1
Paste your XML into the XML input textarea, or click Load sample to use the bundled note document.
- 2
Pick the Format tab for pretty-printed, two-space-indented output.
- 3
Switch to the Minify tab when you want a single-line, whitespace-stripped version instead.
- 4
Read the red alert if validation fails — it names the mismatched or unclosed tag and its position.
- 5
Download the result as formatted.xml or minified.xml from the result box.
Common use cases
- Making a minified RSS or sitemap payload readable before debugging it.
- Compressing XML responses for storage or transport when the consumer does not need formatting.
- Finding mismatched tags in a hand-assembled document before feeding it to a parser.
- Formatting SOAP request envelopes for documentation and code review.
- Preparing pretty-printed SVG or XSLT source for a commit while keeping the working copy minified.
- Validating config exports from legacy systems before importing them into a new pipeline.
Best practices
- Always run the Format pass first — it validates well-formedness, so a clean format output doubles as a validity check.
- Remember that minification trims whitespace-only text nodes; if a text node is significant, do not rely on the minified form.
- Fix validation errors top-down: the first reported mismatch usually reveals the real problem, with later errors cascading from it.
- Keep the XML declaration at the very start of your input so both modes treat it as a processing instruction rather than text.
- Compare Input bytes versus Output bytes when minifying large feeds to confirm the compression actually helped.
- Download rather than copy-paste long outputs, since the file preserves line endings exactly.
Tips
- Load the sample first — it demonstrates both tabs and shows what a well-formed, minifiable document looks like.
- Watch the Lines stat: formatted output jumps to many lines, while minified output is always one.
- Paste minified XML you receive from an API straight into the Format tab to understand its structure quickly.
- Use the download button for feeds and sitemaps; copy-paste can mangle long single-line documents.
Frequently asked questions
Explore more developer tools
Browse the full collection of developer tools on the hub, or jump back to all categories.