XML Formatter & Validator

Indent, minify and validate XML without losing a single comment or CDATA block.

Runs in your browser
XML
Drop file to load it
EmptySaved locally
Formatted XML
Ready
More options (3)
Removes line breaks and spaces at the start and end of the text inside a tag. Off keeps text exactly as written.
Comments that sit between tags are dropped. Comments inside text content stay.
Splits opening tags that would be wider than 100 characters.
Try an example:

How to use the XML Formatter & Validator

  1. Paste XML on the left, or open or drop a file. SVG, RSS, XHTML and most config files are XML too.
  2. 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.
  3. Choose 2 spaces, 4 spaces or tabs, or switch to Minify to put everything on one line.
  4. 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.

This tool runs entirely in your browser. What you type or open is never sent to a server.

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 &lt; and &amp; 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.