XML Formatter & Validator
Indent, minify and validate XML without losing a single comment or CDATA block.
How to use the XML Formatter & Validator
- Paste XML on the left, or open or drop a file. SVG, RSS, XHTML and most config files are XML too.
- The indented version appears on the right. If the document is not well formed, the message points to the line and column and says what to change.
- Choose 2 spaces, 4 spaces or tabs, or switch to Minify to put everything on one line.
- Copy the result or save it as an .xml file.
Examples
About this tool
Machine-generated XML often arrives as one endless line, and hand-written XML drifts into uneven indentation. This formatter reads the whole document, checks that every tag is closed in the right order, and writes it back with one element per line and a consistent indent. It can also minify, removing the whitespace between tags so a payload or feed takes up less space.
The output means exactly what the input meant. Comments, CDATA sections, processing instructions, the XML declaration and the DOCTYPE are copied through unchanged, attributes keep their order, quotes and values, and entities such as & stay as written. Text gets special care: an element that holds text next to child tags, such as a paragraph with a bold word in it, is kept on one line exactly as written, and elements marked xml:space="preserve" are left alone, because adding line breaks there would alter the content.
Validation is strict about well-formedness. Unclosed or misnested tags, attributes without quotes, a bare & or < in text, two root elements, or a declaration that is not at the very start are all reported with their line and column. Tip: when another program rejects an XML file and only says "syntax error", paste the file here to see where the problem is.
Frequently asked questions
Does formatting change my data?
Only whitespace that sits between tags is added or removed. Text inside elements, attribute values, comments, CDATA and processing instructions are copied exactly. If an element contains text next to child tags, its whole content is left untouched, since inserting line breaks there would alter the text. Switch on "Trim spaces around text" under More options if you also want leading and trailing whitespace inside tags removed.
What does "well formed" mean?
That the document follows the XML syntax rules: one root element, every opening tag matched by a closing tag in the right order, attribute values in quotes and never repeated on one tag, and the characters < and & written as < and & in text. Well formed is not the same as valid: this tool does not check a document against a DTD or an XML Schema.
Why does it complain about my XML declaration?
The <?xml ... ?> declaration is only allowed as the very first characters of a document. Even a blank line or a space before it makes parsers reject the file, so the tool reports it rather than quietly fixing it. Delete whatever comes before the declaration.
Is my XML uploaded to format it?
No. The document is read and rewritten by code running in your browser and nothing is sent over the network. Invoices, exports and configuration files with private details can be formatted without concern.
Can I format HTML or SVG with it?
SVG is XML, so it works. HTML is only accepted when it is written as XHTML with every tag closed; ordinary HTML with unclosed <br> or <li> tags is reported as not well formed, so use a dedicated HTML beautifier for that.