XML Formatter & Validator

Paste XML and get clean, indented markup back — and a straight answer about whether it is valid. Invalid documents get the parser error shown plainly instead of a silent bad result.

Runs in your browser — your code and data never leave this device

How do I format XML online for free?

Paste your XML here: this free online XML formatter adds clean indentation with 2 or 4 spaces, and checks the document is well-formed in the same pass — if something is wrong, the error message names the problem and the line. Comments, CDATA sections and the XML declaration are kept, and nothing is uploaded.

Size: 0 B → 0 B
Input characters: 0

Related tools

How to use the XML Formatter & Validator

  1. Paste your XML into the Input box on the left, or click Sample to load an example catalogue.
  2. Choose 2 or 4 spaces for indentation, then click Format and Validate. Valid XML is indented; invalid XML gets the parser error shown plainly.
  3. Check the element count in the success message, then click Copy output or Download to save the formatted document.
  4. Fix any reported error in the original file and format again — the parser stops at the first problem, so a large file may hide more than one.

For the full picture — the errors that break XML, and how to read parser errors — read our guide: How to Format XML.

Formatting plus validation in one pass

XML is stricter than HTML: every tag must close, attributes must be quoted, and there must be exactly one root element. A formatter for XML therefore does two jobs. First it checks the document with the browser's own XML parser, which is the same strict parser a server or an importer would use. If the document fails, you get the parser's error message instead of a guess. Only if it passes does the formatting step run.

The formatting itself is straightforward: one element per line, children indented under their parent, and elements that hold only text kept on a single line so the output stays compact. Attributes stay on the opening tag, in their original order. Comments and CDATA sections are preserved, and the XML declaration at the top of the file is kept.

The errors that break XML most often

Most invalid XML fails for a small handful of reasons. An unclosed tag is the classic one — XML has no void elements, so every opening tag needs its close. Mismatched case is another: <Title> closed by </title> is an error, because XML tag names are case-sensitive. Unescaped ampersands and angle brackets inside text are a third — a bare & in a product name must be written as &amp;, and a < in a comparison as &lt;.

Two structural errors round out the list: more than one root element, and text or markup sitting outside the root. The parser stops at the first problem it meets, so a large file often hides two or three errors — fix the reported one, format again, and repeat until the document passes cleanly.

When to format, when to leave it alone

Format XML when a human has to read or fix it: a configuration file, an API response you are debugging, a sitemap, an RSS feed, a data export. Indentation turns a single dense line into a structure you can scan, and the element count in the success message gives a quick sense of the document's size.

Leave it minified when only machines read it. A feed or an API response that travels over a network is smaller and faster as one line, and formatting it would only add bytes. The rule is the same as for JSON: pretty-print for people, compact for transport, and never edit the minified copy by hand when a formatted one exists.

Format and validate in one pass: indentation plus error checks

To pretty print XML online free, paste it and the formatter indents every element by its depth, so the structure is visible at a glance — with 2 or 4 spaces, your choice. The same pass runs your browser's XML parser over the document, so a missing closing tag or a mismatched element is caught at once, with an error message that names the problem and the line it sits on.

What it keeps matters: comments and CDATA sections survive formatting intact, and the XML declaration is carried through, so the formatted document is still the same document. One honest limit: this checks well-formedness only — that the XML is correctly structured — not validity against a schema or DTD, which needs a dedicated validator. It also formats only; there is no minify mode here.

Frequently asked questions

What does the validator check?

It checks well-formedness: one root element, every tag closed, matching case, quoted attributes and no stray text outside the root. It uses the browser's own XML parser, so the verdict matches what a server or importer would say.

Why does my XML fail with a parser error?

The usual causes are an unclosed tag, mismatched tag case, an unescaped ampersand or angle bracket in text, or more than one root element. The error message names the problem and usually the line, so fix that spot and try again.

Are comments and CDATA sections kept?

Yes. Comments are preserved in place, CDATA sections are kept intact, and the XML declaration at the top of the file is carried over to the formatted output.

Does it check against a schema or DTD?

No. This tool checks that the document is well-formed XML, not that it matches a particular schema, DTD or expected structure. Schema validation needs a dedicated validator.

Is my XML uploaded anywhere?

No. This tool runs entirely in your browser using JavaScript. Your data is never uploaded, stored or sent anywhere — everything stays on this device.

What is the difference between well-formed and valid XML?

Well-formed XML is correctly structured: every opening tag has a matching closing tag, elements nest properly, and there is one root element. Valid XML goes further — it also follows the rules of a schema or DTD. This tool checks well-formedness; checking against a schema needs a dedicated validator.

Can I format XML with 2-space or 4-space indent?

Yes — choose 2 or 4 spaces. Two spaces keeps deeply nested documents compact, while 4 spaces makes the structure easier to scan. Pick the one your project already uses so the formatted XML matches the rest of your files.

Does the formatter keep the XML declaration?

Yes — the declaration at the top of the document is carried through formatting unchanged, along with comments and CDATA sections. The formatted document is the same document, just indented.