How to use the XML formatter
- Paste, drop or open an XML document in the left pane.
- Choose Indent: 2 spaces, 4 spaces, Tabs or Minify.
- If the document is well-formed, the formatted XML appears on the right and the status bar shows the number of elements. If not, the error and its line and column are shown instead.
Example
<?xml version="1.0"?><!-- feed --><root a="1"><item id="1">A & B</item><item id="2"/></root>
becomes
<?xml version="1.0"?>
<!-- feed -->
<root a="1">
<item id="1">A & B</item>
<item id="2"/>
</root>
The declaration, the comment, the attribute order and the & entity are all kept. Empty elements are written in self-closing form, so <empty></empty> becomes <empty/>.
Well-formedness errors
The document is checked before formatting, and the first problem is reported with its position:
| Input | Error |
|---|---|
<root><a></b></root> |
Expected closing tag 'a' (opened in line 1, col 7) instead of closing tag 'b'. |
<root><a>1</a> |
Unclosed tag 'root'. |
Click Jump to error to move the cursor to the reported line.
Common causes of well-formedness errors:
- A raw
&in text or attributes, as inTom & Jerry. Write it as&. - A raw
<in text, as in1 < 2. Write<or wrap the text in a CDATA section. - HTML habits such as
<br>or<img src="x">without a closing slash. In XML they must be<br/>and<img src="x"/>. - Unquoted attribute values, such as
id=1instead ofid="1". - Text before the first element, such as a stray word pasted above the document.
- More than one top-level element, such as
<a/><b/>. A document has exactly one root element (XML must have exactly one root element; found 2.). - A bare
&inside an attribute value, such astitle="R&D"— writeR&D.
What changes and what doesn’t
| Kept as written | Normalized |
|---|---|
| Comments, CDATA, processing instructions, DOCTYPE | Indentation and line breaks between elements |
| Attribute order and values | Empty elements become self-closing |
Entities such as & and © |
Whitespace-only text between elements |
Mixed content, such as <p>Hello <b>world</b> again</p> |
Elements that mix text with child elements are written on one line exactly as they appear, because whitespace inside them is significant — <p>Hello <b>world</b> again</p> keeps its spaces. Elements that contain only child elements are indented one level per depth, and an element with a single text or CDATA child stays on one line.
Related tools
- Convert the document to JSON with XML to JSON, or go the other way with JSON to XML.
- Compare two versions of a config with Text Diff.
- Escape XML for embedding in a JSON string with JSON Escape / Unescape.
Doing it locally
xmllint --format feed.xml # libxml2: validate and pretty-print
xmllint --noblanks feed.xml # remove ignorable whitespace
Frequently asked questions
Is my XML uploaded?
No. Validation and formatting run in your browser and nothing is uploaded, so SOAP payloads, configs and feeds stay private.
Does it validate against a schema (XSD or DTD)?
No. It checks that the document is well-formed: every tag is closed, tags nest correctly and attributes are quoted. Validating against an XSD or DTD needs a schema-aware validator.
Are comments and CDATA kept?
Yes. Comments, CDATA sections, processing instructions and the XML declaration are preserved, and attributes keep their original order.
Are entities like & decoded?
No. Entities and character references are kept exactly as written, so A & B stays A & B and the document means the same thing after formatting.
What does Minify do?
It removes the indentation and line breaks between elements and writes the whole document on one line, which is useful before embedding XML in a request or a string.
Last updated