XML Formatter

Indent or minify an XML document without changing what it says, entirely in your browser.

Runs entirely in your browser. Nothing is uploaded, logged or stored.

Paste an XML document and read it. Indentation, or the whole thing back on one line — and nothing else changed, because in XML most of what a formatter would like to tidy is data.

How it works

An HTML formatter can indent freely between block elements, because a browser renders no whitespace there. XML has no block elements and no inline ones. It does not know what a single one of your elements means, and whitespace inside an element that holds text is part of that text.

So the rule here is narrow, and it is the whole tool: an element is re-indented only when it holds another element and no text of its own. Anything else — text, mixed content, CDATA, a leaf holding nothing but spaces, an element marked xml:space="preserve" — comes back byte for byte.

Inside a start tag whitespace is never data, so runs of it between attributes become one space. What is inside the quotes is left alone. Attributes are never reordered, renamed or re-quoted.

The tags have to balance before any of this happens. A document whose closing tag does not match, or that opens an element and never closes it, is refused rather than tidied: a formatter that indents broken markup hands back something that looks right and is wrong in a new way.

Examples

Case Input Result
Mixed content is left exactly as it is <p>Paper <em>and</em> cloth.</p> <p>Paper <em>and</em> cloth.</p>
A leaf holding spaces keeps them <value> </value> <value> </value>
Attributes get one space between them <a b="1" c="2"/> <a b="1" c="2"/>

Frequently asked questions

Why did my document come back on one line?

Because its root element holds text as well as elements. That is mixed content, and the whitespace in it is data: indenting would insert characters your document did not have. The formatter is working — it is refusing to edit your content in order to make it prettier.

Does it check my XML against a schema?

No. It checks that the tags balance, which is what it needs in order to indent anything, and nothing more. To check a document against an XSD, use the XML validator.

Does anything leave my browser?

No. The formatter is JavaScript running on your machine; the document is never sent anywhere, which is the only sensible arrangement for a file you are pasting in to have its whitespace changed.

Why are my attributes not on separate lines?

Because a start tag has no nesting to show. Breaking one across lines is a matter of taste rather than structure, and this formatter only does the things that have one right answer.

What does "on one line" remove?

Only the whitespace between elements, in the same places indenting would have added it. Text, CDATA and comments are untouched, so the document still says exactly what it said.

Good to know

  • A layout pass, not a parser. Namespaces are not resolved, entities are not expanded, no value is normalised and nothing is checked against a schema.
  • Encoding is your browser's. The declaration at the top of the document is carried through unchanged, whatever it says.

All Code tools