Data & Formats

XML Formatter & Validator

Pretty-print XML with your choice of indentation, minify it to one line, and find well-formedness errors with line and column numbers.

Guide: XML Formatter and Validator: Fix Well-Formedness Errors

Ready.

What it does

The formatter parses your XML with the browser's XML parser. If the document is well-formed it is rewritten with consistent indentation; if not, you see the line and column of the first error, such as a mismatched closing tag.

Notes

  • Attributes, namespaces, comments, CDATA sections and processing instructions are preserved, and an XML declaration at the top is kept.
  • Formatting trims whitespace around text and drops whitespace-only text between elements. This is safe for most data files, but if your document depends on exact whitespace inside mixed content, compare before using it.
  • DOCTYPE declarations with an internal subset and ENTITY declarations are rejected on purpose, as they are a common source of security problems.

Example

Formatting this document with a 2-space indent:

<a><b>text</b></a>

gives:

<a>
  <b>text</b>
</a>

In Minify mode the same tool does the reverse: <a>\n <b id="1">x</b>\n</a> becomes <a><b id="1">x</b></a>.

Common XML errors and how to fix them

The messages come from your browser’s XML parser, so their wording can differ a little between browsers. The line and column point to the first problem:

  • Mismatched tags. <a><b></a> gives “Opening and ending tag mismatch: b line 1 and a.” Close b before you close a.
  • Unescaped ampersand. <a>1 & 2</a> gives “xmlParseEntityRef: no name.” Write &amp; for an ampersand, and &lt; for a less-than sign.
  • Two root elements. <a/><b/> gives “Extra content at the end of the document.” An XML document has exactly one root element, so wrap both in a parent.
  • Unquoted attribute value. <a x=1/> gives “AttValue: " or ' expected.” Write <a x="1"/>.

Frequently asked questions

Does this validate against an XSD or a DTD?

No. It checks that the document is well-formed, meaning the syntax is correct. It does not check it against a schema.

Why is my document with a DOCTYPE rejected?

Internal DOCTYPE subsets and ENTITY declarations are rejected on purpose, because they are a common source of security problems such as entity expansion attacks.

What is the difference between XML and HTML?

XML is stricter: every tag must be closed, attribute values must be quoted and there is exactly one root element. Many HTML pages are not valid XML.

Is my XML uploaded?

No. The formatter runs in your browser.

Privacy

This tool runs entirely in your browser. What you enter is processed on your device and is not sent to a server.

Share this tool

Your data is not included in this link.