XML formatter
Prettify your XML string into a friendly, human-readable format.
About XML formatter
Indents an XML document so its structure is easy to read, with a configurable indent size and an option to keep short text content on the same line as its element. Invalid XML is reported instead of being formatted.
When you would use it
- Reading a minified XML payload, SOAP envelope or configuration file that arrived as a single line.
- Normalising the formatting of an XML file before committing it, so diffs show real changes.
- Checking that an XML document is well-formed.
How to use it
- Paste the XML into the left field.
- Set the indent size (0 to 10 spaces) and toggle "Collapse content".
- Copy the formatted result.
Things worth knowing
- "Collapse content" keeps an element and its text on one line (<name>Ann</name>). Switched off, the text is moved to its own indented line, which is more uniform but longer.
- Formatting changes whitespace between elements, which is usually insignificant. In documents where whitespace inside text matters (mixed content, pre-formatted text), check the result.
- The checker only tests well-formedness: matching tags, proper nesting and quoting. It does not validate against a DTD or XML Schema.
- Comments, CDATA sections and the XML declaration are preserved.
Frequently asked questions
- Why is my XML reported as invalid?
- Common causes are an unclosed tag, an unescaped & or < in text (write & and <), attribute values without quotes, or several root elements. HTML is not XML, so an HTML page usually fails too.
- Can it minify XML instead?
- Not directly. Set the indent size to 0 to remove indentation, which produces a compact but still line-broken document.