99tools

XML Formatter & Validator

runs in your browser

Pretty print or minify XML and catch mistakes by line and column, keeping comments, CDATA and attribute order exactly as they were.

Output
Indent

Only the spacing between tags changes. Comments, CDATA, the declaration and attribute order are passed through untouched.

XML

Formatted

about this tool

Formatting and checking in one pass

Paste XML and get it indented with each element on its own line, or minified back to a single line. Malformed markup is reported rather than silently half-formatted, so this doubles as a quick validity check: if it formats, it is well-formed.

Well-formed is not the same as valid

Worth being precise, because the two words get used interchangeably and mean different things.

Well-formed means the syntax is correct: every tag is closed, elements nest properly, attributes are quoted, and there is a single root. That is what this tool checks, and it is what an XML parser requires before it will do anything at all.

Valid means the document also conforms to a schema — an XSD, DTD or RelaxNG — which says which elements may appear where, in what order, and what types their contents have. A document can be perfectly well-formed and still wrong for its schema. Checking that needs the schema, which this tool does not ask you for.

Options

Strip comments removes <!-- … --> blocks, useful when a generated file carries a licence header you do not need to read again.

Collapse empty elements rewrites <tag></tag> as <tag/>. The two are exactly equivalent to any parser, so this is purely a readability choice.

Indentation can be two spaces, four, or tabs.

Whitespace is data, sometimes

This is the one real caveat with formatting XML, and it is worth knowing before you reformat a document and commit it.

In XML, whitespace inside an element is part of its content. For machine-readable XML — a SOAP envelope, a config file, an RSS feed — nothing cares, and indenting is free. But in a document format with mixed content, where text and elements are interleaved in a paragraph, adding newlines between elements can change the rendered result. If you are formatting XML destined for a rendering pipeline rather than a parser, check the output.

Documents can also declare xml:space="preserve", which is an explicit instruction that the whitespace inside matters.

Converting instead of formatting

If you want XML as JSON rather than tidier XML, use the XML to JSON converter.

Local

Everything runs in the page. XML from finance, government and enterprise systems carries exactly the data that should not be pasted into an unknown website.

questions

What is the difference between well-formed and valid XML?
Well-formed means the syntax is correct: tags closed, elements properly nested, attributes quoted, one root. Valid means it also conforms to a schema such as an XSD or DTD. This tool checks well-formedness; validity requires the schema.
Can reformatting XML change my document?
It can, in one case. Whitespace inside an element is part of its content, so for a document format with mixed content — text and elements interleaved — adding newlines can change the rendered output. For machine-readable XML such as SOAP or RSS, indenting is free.
Are empty tags written as one tag or two?
Either, as you prefer. Collapsing empty elements rewrites tag-slash-tag as a self-closing tag, and both forms are exactly equivalent to any parser, so it is purely a readability choice.
Does it validate against my XSD?
No. It reports malformed markup, which makes it a quick syntax check, but conformance to a schema needs the schema itself and is not something this tool asks for.
I want XML as JSON, not formatted XML.
Use the XML to JSON converter instead, which changes the format rather than just the indentation.