Skip to content
SPCXTools

XML Formatter

Make XML readable with clean indentation — or minify it — and check that it's well-formed.

Runs locally — files never leave your device

Loading tool…

How to use XML Formatter

  1. 1Paste your XML into the Input box, or click Sample.
  2. 2Choose Beautify to indent it, or Minify to remove whitespace between tags.
  3. 3For beautified output, pick 2 spaces, 4 spaces or tabs.
  4. 4If the XML isn't well-formed, the error is shown below. Otherwise copy or download the result.

Format and validate XML

XML is still everywhere: sitemaps, RSS and Atom feeds, SOAP APIs, Android layouts, Maven and .NET project files, SVG graphics, office documents and countless configuration and data-exchange formats. Machine-generated XML usually comes as a single long line that's almost impossible to read. This XML formatter indents it neatly so you can see the structure, checks that it's well-formed, and can also minify it to save space.

Features

  • Beautify with 2 spaces, 4 spaces or tabs.
  • Minify to remove whitespace between tags.
  • Well-formedness check with the parser's error message.
  • Keeps comments, CDATA, DOCTYPE and the XML declaration.
  • Compact output for elements that contain only text, such as <title>Midnight Rain</title>.
  • Copy or download the result as an .xml file.
  • Private: runs entirely in your browser.

Common XML errors

Error Example Fix
Unclosed tag <item>text Add </item>
Mismatched tags <a><b></a></b> Close tags in reverse order
Unescaped ampersand Tom & Jerry Write Tom &amp; Jerry
Unquoted attribute <price currency=USD> <price currency="USD">
Several root elements <a/><b/> Wrap them in one root element
Text before the declaration <?xml ...?> The declaration must be the very first thing

Related tools

Working with other formats? Pretty-print JSON with the JSON Formatter, convert configuration files with YAML to JSON, or compare two XML files line by line with the Diff Checker.

Frequently asked questions

What does "well-formed" mean?
Well-formed XML follows the basic syntax rules — every opening tag has a matching closing tag, elements are properly nested, there is exactly one root element, attribute values are quoted and special characters such as & and < are escaped. The formatter checks these rules and reports the first problem it finds.
Does it validate against a schema (XSD or DTD)?
No. It checks that the document is well-formed, but it doesn't validate it against an XML Schema or DTD. A well-formed file can still contain elements that a particular schema doesn't allow.
Are comments, CDATA and the XML declaration kept?
Yes. Comments, CDATA sections, processing instructions, the DOCTYPE and the <?xml ... ?> declaration are all preserved. Whitespace-only text between tags is removed and replaced by the new indentation.
Will formatting change my data?
Text inside elements is trimmed of leading and trailing whitespace when beautifying, and entities such as & are written in their standard form. If whitespace inside an element is significant, for example in pre-formatted text, use CDATA or check the output.
Is my XML uploaded?
No. Parsing and formatting happen in your browser using its built-in XML parser.