XML Formatter & Validator
Paste XML to format, minify and validate it — with exact line/column error locations, a collapsible element tree, attribute wrapping and one-click copy or download.
Type or paste any XML (or open a .xml file) and the page validates it as you type. When it is
well-formed you can pretty-print it with your choice of indentation, wrap long attribute lists onto their own
lines, sort attributes, minify it back to a single line, explore it as an interactive collapsible tree, and
copy or download the result. When it is not well-formed you get the exact line and column, a caret pointing at
the problem character, and a plain-English explanation for the usual suspects — unescaped ampersands,
mismatched closing tags, unclosed elements and friends.
Your XML
Tip: press Ctrl+Enter (or ⌘+Enter) inside the box to format.
Why XML fails validation — the usual suspects
XML is stricter about syntax than most people expect. Almost every “my XML is broken” report is one of these:
| Mistake | Example | Why it fails |
|---|---|---|
| Unescaped ampersand | AT&T in text | Every & must start an entity reference — write & for a literal ampersand. |
Unescaped < in text | a < b | < starts a tag — write < for a literal less-than. |
| Mismatched closing tag | <a>…</b> | The closing tag must match the open tag exactly — XML tag names are case-sensitive. |
| Unclosed element | <a> with no </a> | Every element that is not self-closing (<a/>) needs a closing tag. |
| Duplicate attribute | <a id="1" id="2"> | An attribute name may appear at most once per element. This tool flags it as a warning. |
-- inside a comment | <!-- a -- b --> | Double dashes are reserved for the --> terminator — use a single dash or reword. |
| Missing or multiple roots | two top-level elements | A document has exactly one root element. This tool also accepts fragments (several top-level elements) when there is no <?xml declaration. |
| Byte Order Mark | invisible character at file start | Some editors write a BOM that is not valid XML — save as UTF-8 without BOM. |
Well-formed vs valid
People use “validate XML” to mean two different things. A document is well-formed when it obeys the XML syntax rules: balanced and properly nested tags, escaped special characters, a single root element, legal names and no stray text outside elements. A document is valid when it is well-formed and conforms to a schema (a DTD or an XML Schema) that defines which elements are allowed, in what order, with which attributes and data types. This tool checks well-formedness — the syntax layer — and reports the exact position of anything that breaks it. Schema validation needs the schema itself and is out of scope for an in-browser tool.
How the error location works
Line and column are 1-based, with the column counted from the start of the line (the same convention as
most editors). The snippet under the error shows a few lines of context with a ^ caret under
the offending character. The parser on this page is written in plain JavaScript — rather than relying
on DOMParser, whose error messages are terse and vary between browsers — so every error
can point at the exact line and column with an actionable message.
Nothing on this page leaves your browser: there is no server round-trip when you paste, format or validate, no analytics on your inputs, and no storage of any kind.