XML Formatter
Beautify, minify and validate XML online. Syntax errors are reported with line and column numbers, and comments and CDATA are kept intact. Free browser tool.
Beautify and validate XML
XML from an API, a SOAP service or a log file often arrives as one very long line. This tool validates it and then re-indents it so you can see the structure. If the document is not well-formed, you get the error along with its line and column number, so you know exactly where to look. A Minify mode removes the formatting again when you need compact output.
Comments, CDATA sections and processing instructions are preserved, because the formatter works on the document's tokens and leaves your content as it is.
Example
A compact document before and after beautifying. Short text elements stay on one line, and special sections are untouched.
<catalog><!-- Spring list --><book id="b1"><title>XML & You</title><price currency="USD">19.99</price></book></catalog>
<catalog>
<!-- Spring list -->
<book id="b1">
<title>XML & You</title>
<price currency="USD">19.99</price>
</book>
</catalog>Rules for well-formed XML
These are the errors you are most likely to run into when a parser rejects a file:
- Every start tag needs a matching end tag, or must be self-closing, as in
<br/>. - Tag names are case-sensitive, so
<Item>cannot be closed with</item>. - Elements must nest properly, closing in reverse order of opening.
- A document has exactly one root element.
- Attribute values must be in quotes.
- The characters
<and&in text must be written as<and&, or placed inside CDATA.
Well-formed is not the same as valid
This tool checks whether a document follows XML's syntax rules. It does not check against an XSD or DTD, which is what proves that the required elements and data types for a specific format are present. A file can pass here and still be rejected by a system that expects a certain schema.
When to minify
Minifying removes whitespace between tags to make the payload smaller, which helps with SOAP messages and feeds. Turn on Remove comments to strip those as well. The size saving is shown under the output. Be careful with mixed content such as <p>Hello <b>world</b></p>, where spaces inside text are meaningful, and check that the receiving system handles the result the way you expect.
Frequently Asked Questions
Why do I get an error about an unescaped ampersand?
A bare & is not allowed in XML text. Write it as & or wrap the text in a CDATA section.
Does formatting change my data?
It adds or removes whitespace between elements. Text inside elements and CDATA stays as is, though systems that treat whitespace as significant may notice the change.
Can it format HTML?
Only if the HTML is also well-formed XML. Most real HTML is not, because tags like <br> have no closing tag.
How do I convert XML to JSON?
Use our JSON to XML Converter and choose the XML to JSON tab.