What it does
The XML Formatter indents XML so its structure is easy to read, compresses it to save space, or turns it into an escaped string. It checks that the document is well-formed as it goes and shows how many elements it contains, so you notice an unclosed tag before a parser rejects the file.
Broken XML is repaired rather than rejected: tags left open are closed, stray closing tags and a tag cut off at the end are removed, attribute values are quoted, a bare & or < is escaped, and log text around the XML is dropped. The status bar lists each fix, and Auto-fix writes the repaired XML back into the editor.
How to use it
- Paste XML into the Input pane, open a file, or click Load sample.
- Choose Beautify to indent, Minify to remove whitespace between tags, or Stringify to get an escaped string for code.
- Pick 2 spaces, 4 spaces or Tab, and untick Keep comments if you want comments removed.
- Copy or download the result. Single and Split switch between one pane and input and output side by side.
Example
<catalog><book id="bk101"><title>XML Developer's Guide</title><price currency="USD">44.95</price></book></catalog>
Beautified with 2 spaces:
<catalog>
<book id="bk101">
<title>XML Developer's Guide</title>
<price currency="USD">44.95</price>
</book>
</catalog>
Good to know
- Well-formed means every tag is closed and nested correctly. It does not check an XSD or DTD schema.
- CDATA sections and the XML declaration (
<?xml …?>) are kept as they are. - Minifying never changes the text inside elements, only the whitespace between tags.
FAQ
Can it format HTML?
Strict XHTML works. For everyday HTML with unclosed tags such as <br> use the HTML Formatter.
How do I turn XML into JSON or into classes? Use the XML to JSON converter, or XML to Code for C#, Java, Go and TypeScript classes.