XML Formatter & Validator

Format & validate XML online

Pretty-print and validate XML with the exact error location highlighted. Comments and CDATA are preserved, and bare ampersands can be fixed in one click — all in your browser.

Ready — paste or type to validate

🔒 100% private — your document is processed entirely in your browser and is never uploaded, logged, or stored.

An XML formatter that pinpoints the broken tag

Paste your XML and Indentio re-indents it cleanly while keeping comments, CDATA, and declarations intact. If a tag is unclosed or mismatched, or an ampersand isn’t escaped, the exact line and column is underlined in red with a clear explanation — no more scanning thousands of lines by hand.

XML failures are unusually frustrating because the parser reports where it gave up, not where you made the mistake. Forget a </item> on line 40 and a strict parser happily reads on until the document ends, then complains about line 4,000. Seeing the structure properly indented is often enough on its own to make the missing tag obvious — the nesting simply stops lining up.

How to use it

  1. Paste or upload your XML (or a .svg, .xsd, .rss…), or load the Sample.
  2. Well-formedness errors are underlined live — hover for the reason and a fix hint.
  3. Click Format to beautify or Minify to compact.
  4. Open Tree view to inspect elements and attributes, then Copy or Download.

Whitespace in XML is not always insignificant

This is the one genuine difference between formatting XML and formatting JSON, and it catches people out. In JSON, whitespace between tokens carries no meaning at all, so a formatter can rearrange it freely. In XML, the characters between tags are the element’s text content. Re-indenting can therefore change data:

<!-- Before: the element contains exactly "Ada Lovelace" -->
<name>Ada Lovelace</name>

<!-- Naively re-indented: now contains "\n  Ada Lovelace\n" -->
<name>
  Ada Lovelace
</name>

Indentio only introduces line breaks between element-only content — elements whose children are other elements — and leaves elements containing text exactly as they are. It also honours xml:space="preserve", the attribute the XML specification defines for telling processors that whitespace inside an element is meaningful. If you have a document where indentation genuinely matters and it is not marked, add that attribute before formatting.

The awkward case is mixed content — an element holding both text and child elements, like <p>See <b>this</b> page</p>, common in DocBook, XHTML, and RSS descriptions. There is no way to re-indent mixed content without altering the text, so it is left on a single line. That is deliberate, not a limitation.

What survives a formatting pass

Formatting is a parse-and-re-emit cycle, so it is worth knowing what comes back unchanged:

ConstructTreatment
<?xml version="1.0"?>Preserved, kept on the first line — it is only legal there.
<!-- comments -->Preserved verbatim, including their internal line breaks.
<![CDATA[ … ]]>Preserved byte-for-byte. Content inside a CDATA section is never re-indented or escaped.
<?processing instruction?>Preserved, including stylesheet declarations.
<!DOCTYPE …>Preserved as written.
Attribute orderPreserved. XML defines attributes as unordered, but rewriting them would produce noisy diffs.
Entity referencesLeft as written — &amp; stays &amp; rather than being resolved to a literal character.
Namespace prefixesLeft as written. Prefixes are arbitrary labels, so rewriting them is safe in theory and confusing in practice.

Minifying XML

Minify removes the whitespace between elements, which is the mirror image of formatting and carries the same caveat: it is safe for element-only content and it is applied conservatively everywhere else. Text content, CDATA, and comments are never stripped.

XML minification matters more than JSON minification, because XML is verbose by design — every element name is written twice. On a large SOAP envelope or an RSS feed, removing indentation can cut 20–30% of the bytes. As with JSON, though, most of that saving overlaps with what gzip would have compressed away anyway, so treat it as a readability decision first and a bandwidth decision second.

Formatting specific XML dialects

Everything below is XML, so all of it formats and validates here — but each has its own characteristic failure:

Common XML errors it catches

Well-formed vs. valid XML

These two words are used interchangeably in conversation and mean different things in the specification. Well-formed means the document obeys XML’s syntax: one root, correctly nested and closed tags, escaped special characters, quoted attribute values. That is a property of the markup alone, and it is what this tool checks — it is also what you need 99% of the time, because a document that is not well-formed cannot be parsed at all.

Valid is a stronger claim: the document is well-formed and conforms to a specific schema — a DTD, XSD, or RELAX NG grammar — that says which elements may appear, in what order, and with which attributes. A document can be perfectly well-formed and still invalid against its schema, for example by putting <price> where the schema requires <cost>. Schema validation needs the schema file itself and is on our roadmap.

Encoding, and the invisible character that breaks everything

An XML declaration can name an encoding — <?xml version="1.0" encoding="UTF-8"?> — and when it does, the declaration must tell the truth. A file saved as Windows-1252 but declaring UTF-8 will parse until the first accented character and then fail with an invalid-byte error that points at a character which looks perfectly normal in your editor.

The related trap is the byte-order mark, three invisible bytes some Windows editors write at the start of a UTF-8 file. Many parsers accept it; some report “content is not allowed in prolog” and give you no hint that the offending content is a character you cannot see. If a document looks flawless and still refuses to parse at line 1, column 1, re-save it as “UTF-8 without BOM”.

Go deeper

Frequently asked questions

How do I beautify XML?

Paste your XML and click Format. It is re-indented with your chosen indentation while comments, CDATA sections, and processing instructions are preserved exactly.

What counts as invalid XML here?

This tool checks well-formedness: mismatched or unclosed tags, an unescaped &, < or >, duplicate attributes, missing attribute values, and multiple root elements. Each is reported with its exact line and column.

Can it fix XML automatically?

It safely escapes bare & characters for you. Structural problems such as unclosed or mismatched tags are pinpointed with a clear message rather than rewritten — a wrong automatic guess would silently corrupt your document, so those are left for you to fix.

Will formatting change what my XML means?

For the overwhelming majority of documents, no. But XML — unlike JSON — treats whitespace inside elements as real character data, so re-indenting a document that mixes text and markup in the same element can change its text content. Elements marked xml:space="preserve" are left alone for exactly this reason.

Does it support SVG, RSS, XSD and WSDL?

Yes — they are all XML dialects, so you can format and well-formedness-check any of them. Upload a .xml, .svg, .xsd, .wsdl, or .rss file directly.

Is my XML sent anywhere?

No. Everything is processed in your browser. Your XML is never uploaded, logged, or stored.