An XML formatter that checks the markup first
This XML formatter takes the single-line XML you get from APIs, exports and log files and rebuilds it with one element per line and consistent indentation. Before anything is re-indented, the input is parsed as XML. If a tag is left open or an attribute is malformed, you get an error with a line and column instead of a half-formatted document.
Formatting changes the whitespace between tags, trims the whitespace around text that spans several lines and writes attribute values with double quotes. Element names, attribute values, CDATA sections and the XML declaration come through untouched.
Example
An order exported by a web shop, all on one line:
<?xml version="1.0"?><order id="42"><!-- rush --><customer>Ava</customer><items><item sku="A1" qty="2">Mouse</item><item sku="B7" qty="1"/></items></order>
After Format with the default 2-space indent:
<?xml version="1.0"?>
<order id="42">
<!-- rush -->
<customer>Ava</customer>
<items>
<item sku="A1" qty="2">Mouse</item>
<item sku="B7" qty="1"/>
</items>
</order>
Notice that <customer>Ava</customer> stays on one line. Elements that contain only text are kept compact, which is what most people expect from a beautifier and keeps the output short.
Options and buttons
- Indent – 2, 3 or 4 spaces, or a tab character per nesting level.
- Remove comments – drops every
<!-- ... -->block from the output. It is off by default, so comments are kept in place. - Minify – the reverse operation: removes indentation and line breaks and reports the size before and after.
- Validate – confirms the XML is well-formed and names the root element and the number of elements.
What the formatter preserves
XML is less forgiving about whitespace than JSON, because text is data. The formatter is careful in a few places:
- Mixed content. In
<p>Hello <b>big</b> world</p>, the spaces around<b>are part of the sentence, so such elements are left as they are. - Text inside leaf elements.
<t> spaced </t>keeps its leading and trailing spaces. Text that spans several lines is trimmed: the whitespace before its first word and after its last word is removed. An element that contains only whitespace, such as<a> </a>, becomes empty, and whitespace between sibling elements is replaced by indentation unlessxml:space="preserve"is set. xml:space="preserve"and CDATA sections are output verbatim.- Empty elements keep the form you wrote:
<b/>stays self-closing and<c></c>stays expanded.
One cosmetic change to expect: attribute values are always written with double quotes. <a b='x'> becomes <a b="x">, and a double quote inside such a value is escaped as ", so the meaning does not change.
Errors you will see and what they mean
| Status bar message | Typical cause |
|---|---|
| Expected closing tag 'b' … instead of closing tag 'a' | An element was not closed, or tags overlap like <a><b></a></b>. |
| Unclosed tag 'a' | The document ends before the root element is closed, often a truncated file. |
| char '&' is not expected | A raw ampersand in text. Write & or wrap the text in CDATA. |
| Multiple possible root nodes found | Two top-level elements. XML allows exactly one root. |
| Attribute 'id' is without value | HTML-style <b id=1> or <input checked>. Quote every value. |
| Attribute 'x' is repeated | The same attribute appears twice on one element. |
Tag names are case-sensitive, so <Item></item> is also reported as a mismatched closing tag.
Formatter, validator or viewer?
Use the formatter when you want text to paste back into a file, a ticket or a code review. The XML validator focuses on the error report, and the XML viewer shows the document as a collapsible tree for exploring large files. If you are comparing two versions of a document, format both and run them through XML diff so indentation differences do not hide the real changes.
Privacy
Formatting runs entirely in your browser, and the XML you paste or upload is not sent to our server. Load URL fetches a remote file through our server, and Save & Share stores the input so the link can be opened later; both only happen when you use them.