← All tools

Stays in your browser

XML Formatter — Beautify & Validate Online

Free XML formatter. Beautify, minify, and validate XML entirely in your browser.

Formatting XML without changing what it means

XML is whitespace-sensitive in a way JSON is not. Whitespace between elements is text content unless a schema says otherwise, so re-indenting a document can change its meaning for a consumer that treats mixed content as significant. Formatting is a display change that is not always semantically neutral.

Well-formedness and validity are different requirements. A well-formed document has balanced tags and properly quoted attributes; a valid one also conforms to a schema or DTD. Most messages about invalid XML are really about well-formedness: an unclosed tag, an unescaped ampersand or a closing tag whose case does not match its opening tag.

Two characters cause most of the failures. An ampersand must be written as its entity unless it begins a character reference, and a less-than sign in text must always be escaped because the parser reads it as the start of a tag. These creep in when markup is copied out of a feed and re-encoded by hand.

FAQ

How is validation done?
DOMParser parses the document and surfaces parser errors.
Large files?
Best for small and medium documents; huge XML may be slow.
Uploaded?
No.
Why is my XML invalid?
Check well-formedness first: every tag closed in order, attributes quoted, and no bare ampersands. A document can also be well-formed and still invalid if it does not follow its schema, but a schema error usually names an element, while a well-formedness error names a line.
What is the difference between elements and attributes?
Both carry data, but only elements can nest and repeat in a structured way. Attributes are flat and unordered, so anything with structure or an order that matters belongs in a child element, and attributes are best kept for identifiers and simple metadata.
Does reformatting change the data?
It can. Indentation adds whitespace text nodes, which changes a byte-for-byte comparison and matters to consumers that treat mixed content as significant. Where whitespace must be preserved exactly, the content belongs in a character data section rather than in ordinary text.

Related tools