XML Formatter / Validator

Pretty-print, validate and minify XML in your browser, with line and column error messages, adjustable indentation and attribute sorting.

About this tool

Minified or machine-generated XML is nearly unreadable, and a single unclosed tag or stray ampersand can make a feed, a SOAP payload or a config file fail to load. This tool checks that your XML is well-formed using the browser's own parser, reports the line and column of the first error, and pretty-prints valid documents with the indentation you choose, or minifies them to a single line. It checks well-formedness only (it does not validate against a schema or DTD). Everything runs in your browser. For JSON, YAML and CSV, see the JSON Formatter and the Data Format Converter.

How to use it

  1. Paste your XML into the input box, including the optional <?xml ... ?> declaration.
  2. Click Validate to check it is well-formed, or Format to pretty-print it using 2 spaces, 4 spaces or tabs.
  3. Optionally keep or drop comments and sort each element's attributes alphabetically before formatting.
  4. If there is an error, the message shows its line and column. Fix it and run again, then Copy the result, or click Minify for a compact one-line version.

FAQ

What does well-formed mean, and is that the same as valid?

Well-formed means the XML follows the basic syntax rules: one root element, every tag closed and properly nested, attribute values quoted, and special characters escaped. Valid means it also matches a schema or DTD. This tool checks well-formedness only and does not validate against an XSD or DTD.

Why is my XML reported as invalid?

The usual causes are an unclosed or mismatched tag, an unescaped ampersand or less-than sign in text (write &amp; and &lt;), an unquoted attribute value, two root elements, or content before the XML declaration. The error message names the line and column where the parser gave up, which is often just after the real mistake.

Will formatting change my data?

It only changes whitespace between elements. Elements that contain text keep that text on one line with its content intact, so no significant whitespace is invented, and comments, CDATA sections and processing instructions are preserved (comments can be dropped with the option).

What does minify do?

It removes the line breaks and indentation between elements so the document is as compact as possible, which is useful for payloads and config values. Text content is kept, with runs of whitespace inside text collapsed to a single space.

Which browsers does it work in?

Any current browser, since it uses the built-in DOMParser. Error message wording and position details can differ slightly between browsers because each reports parse errors in its own format.

Is my XML uploaded anywhere?

No. Parsing and formatting are done by your browser, so configuration files, API responses and documents never leave your device.

Related tools

Guides & comparisons

← All tools · Blog · Cheat sheets · FAQ