XML Formatter & Validator
Format, validate and minify XML online. Indent with 2 or 4 spaces or tabs, keep comments, CDATA and declarations intact, and see line and column for any error.
How to use XML Formatter
- 1Paste XML into the input box, or open an .xml file.
- 2Pick Format with 2 spaces, 4 spaces or tabs (optionally one attribute per line), or pick Minify.
- 3Copy the result or download it as a .xml file.
What makes it better
- Mode switch: Format, Minify, Validate, XML to JSON, JSON to XML and Tree
- 2 spaces, 4 spaces or tab indentation, or minified output
- Attributes keep their order and text is never changed
- Keeps comments, CDATA, processing instructions and the declaration
- Validate lists every well-formedness problem at once, with line and column
About XML Formatter
XML Formatter indents or minifies XML after checking that it is well-formed. It rewrites only the whitespace between elements: attributes keep their order, text is never altered, and comments, CDATA sections, processing instructions and the declaration stay where they are. Elements that mix text and child elements are left exactly as written, because whitespace inside them can be meaningful. The same page also converts to JSON, converts JSON to XML, lists every problem under Validate and browses the document as a Tree.
Common uses
- Make a minified SOAP response or config file readable before debugging it.
- Shrink an XML payload by removing indentation before sending it.
- Find the missing closing tag or unescaped ampersand in a file that will not load.
- Tidy generated XML so a diff between two versions shows only real changes.
Example
Input
<?xml version="1.0"?><config><!-- main --><server host="localhost" port="8080"><name>api</name></server><motd><![CDATA[Hello <team>]]></motd></config>
Result
<?xml version="1.0"?>
<config>
<!-- main -->
<server host="localhost" port="8080">
<name>api</name>
</server>
<motd><![CDATA[Hello <team>]]></motd>
</config>
Good to know
- Whitespace-only text between elements is treated as formatting and removed or rebuilt. Elements with text and children mixed together, and elements marked xml:space="preserve", are copied unchanged.
- A DOCTYPE, including an internal subset with entity declarations, is kept exactly as written. Nothing in it is expanded or fetched, and entity references in the document are not checked. Validate mode is stricter and lists entity declarations as problems, because the converters refuse them.
- Validation here means well-formed XML: matching tags, quoted attributes, one root element and legal entity references. It does not check the document against a schema or DTD.
XML Formatter FAQ
How do I format XML online?
Paste the XML into the input box and keep the Format mode. Each element goes on its own line, indented by nesting depth. If the XML is not well-formed, an error with the line and column appears instead of a result.
How do I minify XML?
Switch Mode to Minify. Whitespace between elements is removed and the tags join into one line, while text inside elements, comments and CDATA are left as written. The status line shows the input and output sizes so you can see the saving.
Does formatting change my data?
Only the whitespace between elements changes. Attribute order, attribute values, text, entity references, comments, CDATA sections and the declaration are copied as they are, and formatting the result again gives the same output.
What counts as an XML error here?
Mismatched or unclosed tags, unquoted or duplicated attributes, an unescaped ampersand, text outside the root, more than one root element and unknown entity references. Each is reported with its line and column so you can jump straight to it.
Why is one element left on a single line?
Elements that contain text and child elements together, such as a paragraph with a bold word inside, are mixed content. Adding line breaks there would add visible spaces, so they are kept exactly as you wrote them.