Skip to content
Browser tool Runs locally

XML Formatter & Validator

Format, minify, and validate XML in your browser. Runs locally.

XML input
0 chars
Formatted output
Formatted XML will appear here.

Text spacing is preserved by default. Only enable added indentation when your XML content model permits it; this option inserts whitespace where none existed. Neither mode produces canonical XML.

Worked example

Leave added indentation off. The default preserves text spacing, so this already compact document stays unchanged.

XML input

<r><item/></r>

Expected result

<r><item/></r>

What is XML formatting?

The default mode normalizes markup serialization while retaining text whitespace. Enable “Add indentation between elements” only when your application permits new whitespace text nodes; existing text and xml:space="preserve" subtrees remain intact.

What is XML validation?

Well-formedness checking - matching tags, quoted attributes, one root element.

Formatter & Validator vs XML Validator

This combined tool handles both transformation and correctness checking: it can format or minify XML and can also report whether the document is well-formed. Odelvo's separate XML Validator is focused on validation and error diagnosis rather than producing formatted output.

Common XML errors

  • Unclosed tag - an opening tag with no matching closing tag.
  • Mismatched tag - a closing tag that doesn't match the most recent opening tag.
  • Unquoted attribute - an attribute value missing its surrounding quotes.
  • Unescaped ampersand - a raw & in text content instead of the &amp; entity.
  • Multiple root elements - content after the first top-level element closes.

A practical formatting example

For <r><item/></r>, the default keeps the text structure unchanged. With added indentation enabled, element-only branches gain line breaks and the selected two- or four-space indentation. Mixed content such as <p><b>Hello</b> <b>world</b></p> stays inline so its existing space is retained.

Namespaces, CDATA, and entity escaping

Namespace declarations (xmlns attributes) and prefixes are preserved as-is during formatting. CDATA sections keep their raw contents untouched, since reformatting the text inside them could change its meaning. Special characters in ordinary text content - ampersands, angle brackets, and quotes - must use their entity equivalents to be well-formed; the validator reports these as errors rather than silently escaping them.

Browser-based limitations

Because parsing happens with the browser's native XML parser, this tool checks well-formedness only - it does not validate against an external DTD or XSD schema, and it won't fetch external entities or DOCTYPE references over the network. Very large documents are also limited by available browser memory rather than a server-side processing limit.

Frequently asked questions

Is my XML uploaded to a server?
No. Parsing, formatting, and validation run entirely in your browser.
Difference between well-formed and valid XML?
Well-formed means syntax is correct: tags close, attributes are quoted, and there's one root element. Valid means it also conforms to a separate schema, such as a DTD or XSD. This tool checks well-formedness; it does not check against a schema.
How does formatting handle CDATA sections?
Content inside a CDATA section is left untouched, since it may contain characters like less-than signs that would otherwise need escaping; text whitespace is preserved by default. Added indentation is an explicit option for content models that permit it.
Do I need to escape special characters myself?
Characters like an ampersand or a less-than sign inside text content need to be escaped as entities such as &amp; and &lt; before the document is well-formed. The validator will flag an unescaped character with a parse error rather than fixing it automatically.
Why does the error position differ between browsers?
Formatting and validation use the browser's built-in XML parser, and different browsers report the line or column of a parse error slightly differently. The error message itself should still point you to the same underlying problem.

Related tools