Developer Tools

XML Formatter and Validator

This tool indents XML so a document's structure is visible, compresses it for transport, and validates it well enough to find the mistake. Unlike HTML, XML has no convention that lets a tool decide whitespace inside an element is unimportant — any character data may be significant — so only the whitespace between elements is touched.

Runs entirely in your browser — nothing you paste is uploaded.

Mode

Reindent so the structure is readable.

Indent

How to

How to use the XML Formatter

  1. 1

    Paste your XML

    Type, paste, or load an .xml file. Validation runs as you type, so a mistake is reported immediately.

  2. 2

    Choose format or minify

    Formatting indents each level so the nesting is clear. Minifying strips the whitespace between elements without touching text content.

  3. 3

    Fix any reported errors

    An unclosed or mismatched tag is reported with the line it occurs on, rather than a bare statement that the document is invalid.

  4. 4

    Copy the result

    Copy the formatted or minified XML, or download it as a file.

Examples

XML Formatter examples

Text content with spacing

Input
<note>hello world</note>
Output
<note>hello world</note>

In XML any character data may be significant, and there is no equivalent of HTML's inline-element convention. Text content is therefore left exactly as written.

Whitespace between elements

Input
<a> <b>x</b> </a>
Output
<a><b>x</b></a>

Whitespace that sits entirely between two tags is formatting rather than content, so it is the only whitespace minification removes.

A CDATA section

Input
<a><![CDATA[ keep this ]]></a>
Output
<a><![CDATA[ keep this ]]></a>

CDATA exists precisely to hold content that must not be interpreted, so its contents are copied through byte for byte.

Why use it

What the XML Formatter gives you

Content is never altered

Only whitespace lying entirely between elements is removed. Text nodes and CDATA sections come through unchanged.

Errors with a location

Validation reports the line where the document stops making sense, which is the difference between a fixable error and a shrug.

Handles large documents

Formatting is a single pass, so a sizeable feed or configuration file reindents without freezing the browser.

Runs in your browser

XML frequently carries invoices, payroll or patient data. None of it is uploaded here.

Good to know

XML Formatter limitations

  • Validation checks that the document is well-formed. It does not validate against a DTD, XSD or RELAX NG schema.
  • Namespaces are preserved but not resolved or rewritten.
  • Entity definitions in a DOCTYPE are left as they are rather than expanded.
  • Attribute order is preserved, which is correct, but means two semantically identical documents can still differ textually.

Summary

XML Formatter in short

  • Only whitespace between elements is removed; text content is untouched.
  • CDATA sections are preserved exactly.
  • Validation is well-formedness only, not schema validation.
  • Errors are reported with the line number where they occur.
  • Everything runs in your browser.

FAQ

XML Formatter questions

Why is whitespace inside an XML element left alone?

Because XML has no way to know it is unimportant. HTML has a convention that whitespace between inline elements is a word separator and the rest is formatting; XML has no equivalent, so any character data could be meaningful and is preserved.

What is a CDATA section for?

It holds text that would otherwise have to be escaped — markup, code, anything containing angle brackets or ampersands. Since its whole purpose is to be taken literally, its contents are never modified by formatting.

What does validation actually check?

That the document is well-formed: every tag closed, correctly nested, one root element, attributes quoted. It does not check the document against a schema, which would require you to supply the schema.

Can I use this for HTML?

Only for HTML that happens to be well-formed XML. Real HTML has void elements like <br> that are never closed and attributes without quotes, all of which are errors in XML. Use the HTML formatter instead.

Are namespace prefixes handled?

They are preserved exactly as written. Prefixes are not resolved to their URIs or rewritten, since doing so would change a document that other tools may be comparing textually.

Should the XML declaration stay at the top?

Yes, and it must be the very first thing in the file with nothing before it, not even whitespace. That is why a document sometimes fails to parse after being edited — a blank line crept in above the declaration.

What if my file declares a non-UTF-8 encoding?

The text is processed as UTF-8 regardless, since that is how the browser has already decoded it. The declaration is preserved, but it will no longer describe the bytes if you save the result.

How large a document can it handle?

A few megabytes formats comfortably. Beyond that the browser holds both input and output in memory at once, so a very large feed may become sluggish or fail outright.

Is my XML uploaded for formatting?

No. It is processed in this page. That matters given how often XML carries exactly the data you cannot paste into a random website — invoices, payroll records, health data.

Discover

Related developer tools