Skip to the tool

XML formatter

MDV Tools

Paste XML. Get it indented or minified, and told where it stops being well-formed.

Runs on this device Works offline
0 bytes
Result
paste xml above
How this works

The text is handed to the browser's own XML parser, the same one it uses for real documents, and then walked node by node to write it back out with indentation. That means well-formedness is judged by a real parser rather than by pattern matching: a missing close tag, a stray &, a second root element or a mismatched name is reported with the line and column the parser stopped at, and the line itself is printed with a caret under the spot. XML is case-sensitive and every tag must close, so <BR> and <br> are different elements and neither may stand alone.

Only the whitespace between elements is touched — the line breaks and indentation of the layout itself. Anything holding text, text mixed with child elements, or nothing but whitespace is written out on one line exactly as it came in, because in XML those spaces are part of the content and a formatter that reflows them changes the document: <b>  </b> survives both indenting and minifying. Strictly speaking the whitespace between elements is content too, and only a DTD or schema can say it is ignorable; that is the one liberty a formatter takes, and it is the reason indented XML and minified XML are both readable at all. Comments, processing instructions, CDATA sections and attribute order are kept. Attribute values are re-quoted with double quotes and their special characters escaped, which is what the serializer does; empty elements come back in the short <name/> form.

What the page does not do: it does not validate against a DTD or schema, it does not resolve external entities or fetch anything a DOCTYPE points at, and it does not reformat namespaces or rewrite prefixes. Well-formed is not the same as valid — a document can be perfectly well-formed and still break the schema it claims to follow. Input is capped at 2 MB; past that the page refuses rather than lock the tab.

Everything happens in this tab. Nothing is uploaded and nothing you paste is stored; the Dark button keeps its own setting in this browser's local storage.