XML Formatter

Validate, pretty-print and minify XML — with real nesting, attributes, CDATA, comments and mismatched-tag errors.

100% FreeNo sign-upPrivate — runs in your browser
Copied to clipboard

How to use this tool

1
Paste your XML

A fragment with one root element, or a full document with a declaration.

2
Choose indent

2 spaces, 4 spaces or tabs.

3
Format or minify

Format expands nesting readably; Minify compresses to one line.

4
Fix errors by position

Mismatched or unclosed tags are reported with their location instead of being silently corrected.

Formula & worked example

Pretty printing walks the parsed tree: each element level adds one indent, text-only elements stay on one line, and attributes keep their original values (escaped). Minifying drops inter-element whitespace and re-serialises compactly.

<catalog><book id="bk101"><title>XML Guide</title></book></catalog> formats to a nested tree with <book> indented under <catalog>, and a CDATA section like <![CDATA[Price < 10]]> survives untouched.

Limitations — read this before you rely on it

This is a well-formedness checker and formatter, not a validating parser: it does not check against a DTD or XSD, does not resolve external entities (by design, for safety), and namespaces are treated as plain names. Documents with multiple roots are rejected, as the XML standard requires.

Frequently asked questions

Most often: mismatched tags (<a><b></a>), unclosed tags, multiple root elements, unquoted attribute values, or a stray < in text (use < or CDATA).

A section <![CDATA[…]]> whose contents are taken literally — < and & inside it need no escaping. Useful for code samples and comparisons.

Format is for humans reading structure. Minify is for transport and storage — same data, no whitespace.

Yes — comments and processing instructions are kept in place when formatting.

No. It checks well-formedness (structure) only, not whether your elements match a DTD or XSD.