Paste messy XML and read it in seconds
Cramped, single-line XML is nearly impossible to debug. Paste it above and this XML formatter instantly indents every element so the structure is obvious at a glance — no sign-up, no upload, nothing to install.
Every byte stays in your browser. Your config files, API responses, and feed data never leave your machine.
Quick before → after
<!-- Before: hard to read -->
<order id="42"><item><name>Widget</name><qty>3</qty></item></order>
<!-- After: formatted -->
<order id="42">
<item>
<name>Widget</name>
<qty>3</qty>
</item>
</order>One XML rule worth knowing: every tag must be closed, there must be exactly one root element, and tag names are case-sensitive (<Name> ≠ <name>). Formatting only changes whitespace — your actual data is never altered.
How to use the XML formatter
- Paste your XML into the editor above.
- Click Format (or press the keyboard shortcut shown).
- Copy the indented output or download it as a file.
If your XML has a syntax error — a missing closing tag, for example — the tool highlights exactly where the problem is so you can fix it fast.
Worked example
Say you pull a product feed from an API and it comes back as one long string:
<catalog><product><id>101</id><name>Laptop Stand</name><price currency="USD">49.99</price><stock>true</stock></product></catalog>After running it through the XML beautifier you get:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product>
<id>101</id>
<name>Laptop Stand</name>
<price currency="USD">49.99</price>
<stock>true</stock>
</product>
</catalog>Attributes stay on their element, child nodes are indented two spaces, and the data is byte-for-byte identical to what you started with — just readable now.
Format XML in Python or JavaScript
Need to pretty-print XML in code? Here are the shortest working snippets for the two most common languages.
Python
import xml.dom.minidom
raw = '<catalog><product><id>101</id></product></catalog>'
pretty = xml.dom.minidom.parseString(raw).toprettyxml(indent=' ')
print(pretty)The built-in xml.dom.minidom module ships with Python — no extra install needed. toprettyxml(indent=' ') uses two spaces per level.
JavaScript (Node.js)
// npm install xmlbuilder2
const { convert } = require('xmlbuilder2');
const raw = '<catalog><product><id>101</id></product></catalog>';
const pretty = convert(raw, { prettyPrint: true });
console.log(pretty);The xmlbuilder2 library handles both parsing and serialisation. One npm install and you're done.
How it works
The formatter parses your raw text into a DOM tree (a structured map of every element and attribute). It then walks that tree and re-serialises it — writing each node on a new line with consistent indentation. No data is changed; only whitespace is added between tags.
The W3C defines the rules that govern well-formed XML — every formatter follows the same standard. You can read the official spec at w3.org/TR/xml.
When to use an XML formatter (and when not to)
| Use it when… | Skip it when… |
|---|---|
| Debugging API responses or config files | You need to convert XML to JSON or CSV |
| Reading SOAP payloads or RSS/Atom feeds | The file is huge (100 MB+) — use a desktop editor instead |
| Reviewing SVG or XHTML markup | You need to validate against an XSD schema (use an XML validator) |
Tidying Maven pom.xml or Android manifests | Your file is actually HTML — use an HTML formatter instead |
Paste your XML above and get a clean, indented result right now — no account required.