XML Formatter
Format XML with readable indentation and validate its structure.
Your result will appear here…
How to use XML Formatter
- Paste your XML.
- Select Format.
- Copy the indented result.
Example
Input / settings:
<catalog><item id="1"><name>Notebook</name></item></catalog>
Output:
<catalog>
<item id="1">
<name>Notebook</name>
</item>
</catalog>Formatting the output again returns the same text.
When to use
- Read a compact XML response.
- Tidy a configuration file before you commit it.
- Check how elements and attributes nest.
Overview
XML Formatter parses your document with the browser's XML parser and writes it back with each element on its own line, indented by two spaces. It keeps comments, processing instructions, CDATA sections and the XML declaration, and it reports an error for malformed XML. It does not preserve whitespace inside text, and it leaves out the DOCTYPE.
Supported input
XML text
Output details
formatted XML
Limitations
- Text nodes are trimmed and xml:space is ignored, so whitespace inside text and mixed content is not preserved.
- The DOCTYPE is not written and entities defined in it are expanded. Error wording comes from the browser's XML parser.
Common mistakes
- Whitespace in text is not preserved. Each text node is trimmed, so xml:space="preserve" is ignored: <a xml:space="preserve"> keep this </a> becomes <a xml:space="preserve">keep this</a>.
- Mixed content is written one node per line. <p>a <b>b</b> <i>c</i></p> becomes four lines, which changes the whitespace between the inline elements, so avoid formatting XHTML-style text when exact spacing matters.
- The DOCTYPE is not written, and entities defined in it are expanded: a document that defines <!ENTITY e "x"> and uses &e; comes back as <a>x</a>.
- Character references are decoded. © is written as ©, while < and & stay escaped.
- Line breaks inside attribute values become spaces, because XML parsers normalize attribute values. An empty element such as <a></a> is written as <a/>.
Practical tips
- If the formatter reports an error, run the text through XML Validator; both use the browser's parser, and Chrome includes the line and column.
- Attribute order is kept and values are written with double quotes, so a diff against the original shows only whitespace and quoting changes.
Privacy and security
This tool runs entirely in your browser. Your input is never uploaded to our servers. The XML is formatted in your browser and is never uploaded. The tool re-serializes the parsed document, so treat its output as a copy of the data, not as a byte-for-byte equivalent of the input.
References
Frequently asked questions
Does XML Formatter keep CDATA sections and comments?
Yes. Comments, processing instructions and CDATA sections are written back in document order.
Does the XML declaration survive formatting?
Yes. A declaration at the start of the input is copied exactly, including single quotes, as the first line.
Are attributes reordered or requoted?
Attributes keep their order, and values are written with double quotes.