XML Formatter

Minified XML dumps from SOAP services, RSS feeds and config exports are unreadable in a single line. This formatter parses the document, rebuilds it with consistent indentation (2 or 4 spaces, tabs, or no indentation for minified output), preserves attribute order and CDATA sections, and reports any well-formedness issue with the exact line and column so you can fix mismatched tags without hunting.

How to format XML

  1. 1

    Paste XML

    Any length, any encoding; declaration is preserved.

  2. 2

    Pick indentation

    Spaces (2 or 4), tabs, or minify.

  3. 3

    Format

    The parser builds a DOM then re-serialises with consistent spacing.

  4. 4

    Copy result

    Output is well-formed XML ready to paste into logs or docs.

What formatting preserves

  • XML declaration (<?xml version="1.0" encoding="UTF-8"?>) kept verbatim.
  • DOCTYPE declarations and internal subsets preserved.
  • Processing instructions (<?xml-stylesheet ?>) kept on their own line.
  • Comments on their own line or inline depending on context.
  • CDATA sections preserved exactly including whitespace inside.
  • Attribute values re-quoted using double quotes if they contain no double quotes, single quotes otherwise.
  • Entity references like &amp;, &lt;, &gt; left as-is unless you enable full entity expansion.

Indentation examples

Input (minified):

<books><book id="1"><title>1984</title><author>George Orwell</author></book></books>

Formatted (2 spaces):

<books>
  <book id="1">
    <title>1984</title>
    <author>George Orwell</author>
  </book>
</books>

Common errors the tool catches

Error Fix
Mismatched closing tag Match opening and closing names
Unclosed element Add the closing tag
Invalid character in tag name Tag names must start with letter or underscore
Duplicate attributes on same element Remove the duplicate
Malformed CDATA Check <![CDATA[ and ]]> pairing
Unescaped < or & in text Use &lt; or &amp;

Well-formed vs valid

  • Well-formed XML follows the syntactic rules: balanced tags, valid characters, proper nesting. The formatter checks this.
  • Valid XML additionally conforms to a schema (DTD or XSD). For that, use the XSD validator.

An XML document can be well-formed without being valid, but not the other way around.

Practical notes

  • XML attribute order is meaningful to some systems (not many modern ones), the formatter preserves input order.
  • Self-closing vs explicit empty tags: <foo/> and <foo></foo> are equivalent in XML; the formatter uses self-closing for empty elements unless you opt out.
  • Namespace prefixes are preserved exactly.

Frequently Asked Questions

Yes. Text inside mixed-content elements and CDATA sections is kept as-is; only whitespace between elements is adjusted for indentation.

Practical limit is around 50 MB in the browser. Beyond that, the DOM parse consumes too much memory. For huge files use a streaming formatter like xmllint on the command line.

Yes. Namespace declarations are preserved on their element; the formatter does not reshuffle them to the root unless you enable “consolidate namespaces”.

No. Parsing and formatting happens in your browser, nothing is transmitted.

Related Tools

Tool available in other languages