XML Formatter & Validator
Pretty-print squashed XML, or strip the whitespace to minify it. Syntax errors such as an unclosed tag are shown with their line and column. To convert to JSON use the XML ⇔ JSON Converter, and for JSON itself try the JSON Formatter.
🔒 Runs in your browser · Your data is never sent to a server
Notes
- Elements that contain text (mixed content such as <p>Hello <b>world</b></p>) are kept on one line and their contents are not reformatted, because whitespace is significant there.
- Whitespace between elements (line breaks and indentation) is rebuilt when formatting and removed when minifying.
- The XML declaration, comments, CDATA, processing instructions, DOCTYPE, attributes, and namespaces are preserved. Only extra spaces between attributes inside a tag are normalized.
- The check covers well-formedness (matching tags, quoted attribute values, and so on). It does not validate against an XSD or DTD.
- External entities and DTD references are never fetched, and nothing is sent anywhere. The reported line and column point to the first problem found.
Glossary
Well-formed
XML that follows the syntax rules: tags are properly nested and closed, there is exactly one root element, and attribute values are quoted.
Mixed content
An element that contains both text and child elements. Whitespace inside the text can matter, so the formatter does not add line breaks there.
CDATA
A section written as <![CDATA[ … ]]> whose contents are treated as plain text, so tags and symbols need no escaping.
FAQ
Why are elements with text left on a single line?
In mixed content such as <p>Hello <b>world</b></p>, whitespace is part of the text. Adding line breaks or indentation would change the content, so the formatter keeps those elements exactly as written.
Can formatting change the meaning of my XML?
Only the whitespace between elements in element-only sections is rebuilt; text, attributes, comments, and CDATA are untouched. If your data relies on xml:space="preserve", check the result by eye.
How do I read the line and column in an error?
The first character of the input is line 1, column 1, and the position is where the first problem was detected. For a mismatched closing tag, the message may also mention where the matching start tag was. The real mistake can sit a little before the reported position.
Does it validate against a DTD or XSD?
No. It only checks that the document is well-formed, such as matching tags and quoted attribute values. External DTDs and entities are never fetched, so no network request is made.
Share this page
