How to use the XML formatter online
- Paste XML, drop an
.xml,.svgor other XML file on the input, or click Open file. Files are read locally. - Choose Beautify and an indent of 2 spaces, 4 spaces or tabs, or Minify to remove the whitespace between tags.
- Tick Remove comments to strip
<!-- … -->blocks from the output. - Copy or download the result.
What “well-formed” means
The W3C XML 1.0 specification calls a document well-formed when it follows the basic syntax rules. A parser must stop at the first violation, so a formatter cannot safely guess what broken XML meant. The rules this XML validator and formatter checks are:
- There is exactly one root element that contains everything else.
- Every start tag has a matching end tag, or is self-closing (
<br/>), and tags close in the reverse order they opened. - Tag names are case-sensitive:
<Item>is not closed by</item>. - Attribute values are in single or double quotes, and an element cannot repeat an attribute.
&and<in text must be written as&and<. Only five named entities are predefined; others such as need a DTD.- The XML declaration, if present, comes first.
After this check passes, the XML is also run through your browser's built-in XML parser, which catches rarer problems such as invalid characters, and any message it reports is shown.
XML beautify rules and whitespace
Pretty printing changes whitespace, and in XML whitespace between tags is usually, but not always, insignificant. This formatter drops text nodes that contain only spaces and line breaks, trims the text inside elements, and keeps comments, CDATA sections, processing instructions and the DOCTYPE exactly as written. Attribute values and their quote style are preserved; only the spacing between attributes is normalised.
<note><to>Tove</to><from>Jani</from><body>Don't forget me!</body></note>
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me!</body>
</note>If your document relies on exact whitespace, for example mixed content in a document format or elements marked xml:space="preserve", compare the output before using it. The text compare tool shows every difference. For JSON data, use the JSON formatter instead.
Well-formed vs. valid XML
“Valid” has a stricter meaning in XML than in everyday speech. A valid document is well-formed and matches a schema (a DTD, XSD or RELAX NG grammar) that says which elements may appear where. This free online XML formatter checks well-formedness only, which is what formatting needs. Schema validation requires the schema file and is usually done in your build or with a tool like xmllint --schema schema.xsd file.xml.