How to format XML online
- Paste your XML into the box, or press Insert example.
- Choose Format and an indent (2 spaces, 4 spaces or a tab), or Minify to strip the whitespace between tags.
- Copy the result or download it as a .xml file. Use as input moves the result back into the box.
The page checks that the XML is well-formed before it prints anything. If it is not, you get the line, the column and the reason instead.
Format and minify: one example
XML as many APIs and exports deliver it, on one line:
<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price>9.99</price></book><book id="b2"><title>Data & Tags</title><price>14.50</price></book></catalog>
Formatted with 2 spaces. Elements that hold only text stay on one line, so <title>XML Basics</title> is not split:
<?xml version="1.0"?>
<catalog>
<book id="b1">
<title>XML Basics</title>
<price>9.99</price>
</book>
<book id="b2">
<title>Data & Tags</title>
<price>14.50</price>
</book>
</catalog>Minified, with whitespace between tags and comments removed (text inside elements is kept, with runs of whitespace collapsed):
<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price>9.99</price></book><book id="b2"><title>Data & Tags</title><price>14.50</price></book></catalog>
Formatting only adds or removes whitespace between tags. If your XML uses mixed content (text and tags in the same element, as in HTML-like documents), whitespace can be significant; check the result before you rely on it.
Well-formed errors and what they mean
XML is much stricter than HTML. These are the mistakes the checker finds, with the message it gives:
| Mistake | Message |
|---|---|
| Tags closed in the wrong order | Not well-formed XML at line 3, column 9: closing tag </a> does not match <c> opened at line 3. |
| An element never closed | Not well-formed XML at line 1, column 1: <a> is never closed. |
| Attribute value without quotes | Not well-formed XML at line 1, column 1: attributes in <note to=Ann> need a name and a quoted value. |
| A bare ampersand in text | Not well-formed XML at line 1, column 9: a bare & must be written &. |
| Two root elements | Not well-formed XML at line 1, column 5: only one root element is allowed; <b> starts a second one. |
The five characters that must be escaped in text are & for &, < for < and, in attribute values, " for the double quote; > and ' are optional. Anything else needs an escape only if it is not in your document's encoding.
What well-formed means, and what it does not
A well-formed document has exactly one root element, every start tag has a matching end tag in the right order (or is self-closing, like <br/>), attribute values are quoted, and special characters are escaped. This tool checks all of that.
It does not validate against a schema (XSD) or DTD, resolve entities such as that need a DTD (use   instead), or check namespaces. A document can be well-formed and still be wrong for the system that reads it: for that you need the schema from that system.
The XML declaration (<?xml version="1.0"?>), comments and CDATA sections are kept as they are. To pretty-print JSON instead, use the JSON formatter; for text encoded as Base64 inside an XML element use Base64 decode.
Related tools
- JSON formatter – the same for JSON
- JSON validator
- Base64 encode and decode – decode Base64 payloads that contain XML
- URL encoder and decoder
XML formatter FAQ
How do I format XML?
Paste the XML, keep Format selected and choose an indent. The indented result appears at once and can be copied or downloaded.
How do I check whether my XML is valid?
The tool checks that it is well-formed: one root, matching tags, quoted attributes and escaped ampersands. An error shows the line and column.
Does it validate against an XSD or DTD?
No. It checks well-formedness only. Schema validation needs the schema file and a schema-aware validator.
Why does my XML say "unexpected characters in a tag"?
A tag has something the parser cannot read, such as an unquoted attribute value or a stray less-than sign. Escape a literal < as <.
Will formatting change the meaning of my XML?
For data-style XML no. Formatting only changes whitespace between tags. In mixed content (text next to tags) whitespace can matter, so check the result.
Is my XML uploaded anywhere?
No. It is checked and formatted in your browser and nothing is sent or stored.