Skip to content
PratronHome

XML Formatter & Validator

Format XML into a readable tree and find out whether it is well-formed at the same time. Unlike HTML, XML has no error recovery — a single unclosed tag makes the whole document invalid — so the tool runs it through a real parser first and shows exactly what went wrong before it reformats.

Developer Tools

Private by default

This tool runs entirely in your browser. Your data is never uploaded to a server.

How it works

Parse first, format second

The document goes through the browser's own XML parser before anything is reformatted. If it comes back with an error, that message is shown as-is — the parser knows more about what went wrong than any summary would.

  • A document must have exactly one root element. Several top-level elements is the most common failure.
  • CDATA sections are preserved intact — their whole point is to hold text the parser must not interpret.
  • Namespace prefixes are left alone. A prefix that was never declared is a well-formedness error the parser reports.
  • The XML declaration and any processing instructions stay on the first line, where the specification requires them.

For reference

The five characters XML reserves

CharacterEntityRequired where
&&Everywhere in text and attributes
<&lt;Everywhere in text and attributes
>&gt;After ]] — escaping it elsewhere is convention
"&quot;Inside double-quoted attribute values
'&apos;Inside single-quoted attribute values

An unescaped & is the single most common cause of a document failing to parse — a raw ampersand in a URL inside an attribute does it every time.

How to use

4 clear steps.

  1. Paste the XML document or fragment.

  2. Check the error box: anything not well-formed is reported there.

  3. Choose your indentation.

  4. Copy the formatted XML.

Good to know

Frequently asked questions

What does well-formed mean?
Every tag is closed, elements nest without overlapping, there is exactly one root element, attribute values are quoted, and the special characters &, < and > are escaped. It is the minimum bar for XML to be parseable at all.
Is well-formed the same as valid?
No. Valid means well-formed and also conforming to a schema — a DTD, XSD, or RELAX NG — which defines which elements may appear where. This tool checks well-formedness; schema validation needs the schema.
Why is XML stricter than HTML?
By design. HTML parsers recover from errors so a broken page still displays something; XML parsers stop, because XML is used for data exchange where quietly guessing at malformed input causes worse problems than refusing it.