Developer Formatting

XML formatter

What to do
Indent

Processed in your browser · nothing is uploaded

Local · well-formedness, not schema validity
Advertisement
320 × 100

Re-indents an XML document by nesting depth, minifies it, or checks it is well-formed using the browser’s own parser.

How to use the xml formatter

1 Paste the XML and choose an indent; two spaces, four, or a tab.
2 Format re-indents by nesting depth; Minify puts it back on one line.
3 Check well-formed runs it through the browser’s own XML parser.
4 Copy the result, or save it as a file.

Well-formed and valid are different things and the difference matters. Well-formed means the syntax holds: every tag closed, correctly nested, one root element, attributes quoted. Valid means it additionally conforms to a DTD or schema saying which elements may appear where. This checks the first and not the second, because the second needs the schema.

Two strictnesses catch people coming from HTML. Tags are case-sensitive, so <Book> does not close <book>. And a bare ampersand is illegal anywhere at all: it starts an entity reference, so a URL with ?a=1&b=2 in it has to be written &amp;b=2 even inside an attribute value. The error the parser gives for that one rarely mentions the ampersand.

The formatter indents by depth without parsing, which sets its limits. It will not tell you a tag is unbalanced; an unclosed element shows up as everything below it drifting one level to the right, which is usually enough to find it. And a CDATA section holding markup is split like any other tag, so a document that embeds HTML that way is better left unformatted.

Minifying is lossier than it looks. Runs of whitespace are collapsed everywhere, text content included, and xml:space="preserve" is not honoured, so an element holding a code sample, a formatted address or anything else where the spacing is the content should not go through it.

Questions

Well-formed is correct syntax. Valid additionally conforms to a DTD or schema. This checks well-formedness.

W3C. Extensible Markup Language (XML) 1.0
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding