XML Formatter guide
Turn a one-line XML blob, SOAP response, RSS feed, or sitemap into readable, indented XML. Invalid documents get a clear error pointing at the broken line.
What this XML formatter does
Paste XML and it gets parsed by your browser's built-in XML parser, the same one that handles SVG and RSS feeds. If the document is well-formed, the tool walks the element tree and writes it back out with one element per line and consistent indentation. If it is not well-formed, you get the parser's error with a line and column instead of a half-formatted mess.
No library, no server. The parse happens in this tab, which matters when the XML is a SOAP response with account numbers, a SAML assertion, or an internal config file. Nothing is uploaded or logged.
Well-formed is not the same as valid
Well-formed means the document follows XML's grammar: one root element, every tag closed, tags properly nested, attribute values quoted, and special characters escaped. That is what this tool checks.
Valid is a stricter idea: the document also matches a schema (XSD, DTD, or RelaxNG) that says which elements are allowed where. A file can be perfectly well-formed and still fail schema validation because an element is missing or out of order. Schema validation needs the schema file and a validating parser, which browsers do not ship.
The errors you will actually see
Mismatched tag: <name>Ada</Name> fails because XML is case-sensitive. Opening and closing tags must match exactly.
Unescaped ampersand: <company>Smith & Sons</company> fails. Write & instead, or wrap the text in a CDATA section. The same goes for a literal < inside text, which must be <.
Multiple roots: two top-level elements side by side is not a document. Wrap them in a single parent.
Content before the declaration: <?xml version="1.0"?> must be the very first thing in the file. Even a blank line or a byte-order mark in the wrong place before it triggers an error in strict parsers.
Undeclared namespace prefix: <media:cover/> needs xmlns:media="..." on it or an ancestor. The parser rejects prefixes it cannot resolve.
Worked example
Input on one line: <catalog><book id="bk101"><author>Gambardella, Matthew</author><price currency="USD">44.95</price></book></catalog>. Formatted with 2 spaces, catalog sits at the left edge, book is indented two spaces, and author and price are indented four with their text kept on the same line as their tags. Empty elements are written in the short self-closing form, like <cover/>.
Comments, CDATA sections, processing instructions, and the XML declaration are preserved. Attribute order stays as written, and special characters are re-escaped correctly on the way out.
Pitfalls
Whitespace in mixed content. Pretty-printing adds line breaks between elements and trims whitespace-only text. For data XML (configs, API payloads, feeds) that is exactly what you want. For document-style XML where text and inline tags mix, such as DocBook, XHTML paragraphs, or <p>Hello <b>world</b></p>, the formatter will move the <b> onto its own line, which changes the rendered spacing. Format those by hand, or only minify them.
xml:space="preserve". Some formats mark elements whose whitespace must not change. This tool does not special-case that attribute, so keep the original for those sections.
DOCTYPE entities. Browsers do not load external DTDs, so custom entities defined in an external DTD (like in some legacy files) will be reported as undefined. Replace them with numeric references such as  .
Huge files. Everything runs on your device, so a 50 MB export will be slow. For files that size, use xmllint --format file.xml on the command line.
Minify versus format
Minify removes the whitespace between tags and puts the document on one line. It is handy for embedding XML in a JSON string, a test fixture, or an environment variable. Over the network, gzip compresses indentation so well that minifying rarely saves much, so keep the readable version in source control.
How we calculate: sources
Frequently asked questions
Does the XML formatter validate my XML?
It checks that the XML is well-formed: one root, matching and properly nested tags, quoted attributes, and escaped special characters. It does not validate against an XSD or DTD schema.
Why do I get an error on a line that looks fine?
XML parsers report where they gave up, which is often just after the real mistake. Check the previous tag for a missing close, a case mismatch, or a bare & character.
Are comments and CDATA kept?
Yes. Comments, CDATA sections, processing instructions, the XML declaration, and DOCTYPE are preserved.
Can I minify XML?
Yes. Minify removes the whitespace between elements and outputs the document on a single line.
Does it handle namespaces?
Yes. Prefixed elements and xmlns declarations are kept exactly as written. Undeclared prefixes are reported as errors.
Is my XML uploaded anywhere?
Everything runs in your browser. Nothing you enter is uploaded to a server or stored by us.
How do I fix an unescaped ampersand in XML?
Replace & with & in text and attribute values, or wrap the text in <![CDATA[ ... ]]>. A bare & is only allowed as the start of an entity reference.
Does formatting change my XML data?
It adds indentation and trims whitespace-only text between elements. Element names, attributes, text values, comments, and CDATA are preserved. Document-style XML with mixed text and tags can change spacing, so check those.