XML Formatter
Format, minify and validate XML in your browser. Errors are reported with their line and column. Your files are never uploaded.
How to format XML
- Paste your XML, or click Open a file to load an
.xml,.svg,.xsd,.xsl, RSS or other XML file (up to 10 MB). - Choose the Indentation: 2 spaces, 4 spaces or a tab.
- Click Format (beautify) for readable, indented XML, or Minify for the most compact version. Validate only checks the document and leaves the result as it is.
- Tick Remove comments to drop
<!-- … -->comments from the result. - Copy or download the result.
Every action first checks that the document is well-formed. If it is not, nothing is changed and the error message gives the line and column of the problem.
What the formatter does
Format (beautify) puts each element on its own line, indented by its depth:
<catalog>
<book id="1">
<title>XML & you</title>
<tags/>
</book>
</catalog>
- An element that only contains text stays on one line, like
<title>above; surrounding whitespace in that text is trimmed. - Attributes keep their order, their values and their quote style; only the spaces between them are normalised.
- Comments, CDATA sections, processing instructions and the XML declaration are kept.
- An element with
xml:space="preserve"is copied exactly as written, whitespace included. - Entities such as
&oréare left untouched: the text is never decoded and re-encoded.
Minify removes the whitespace between tags and, if ticked, the comments. Text content is kept as is. The status line shows the size before and after, in bytes.
What “well-formed” means
A well-formed XML document follows the syntax rules of XML 1.0:
- there is exactly one root element;
- every opening tag has a matching closing tag, properly nested (
<a><b></b></a>, never<a><b></a></b>), or is self-closing (<br/>); - attribute values are quoted, and the same attribute does not appear twice on an element;
<and&in text are escaped as<and&;- names are case-sensitive:
<Title>is not closed by</title>.
The check uses the XML parser built into your browser, so the error messages for the less common cases (undeclared entities, invalid characters, namespace prefixes) come from the browser itself and are written in its language. Being well-formed is not the same as being valid against a DTD or an XSD schema: this tool does not check schemas.
Frequently asked questions
Is my XML uploaded?
No. Formatting and checking happen in your browser; your files never leave your computer.
Why did the spacing in my mixed text change?
In an element that mixes text and child elements, such as <p>Hello <b>world</b></p>, formatting puts the text and the child on separate lines. Whitespace in such content is usually not significant; when it is, use xml:space="preserve" on the element, or use Minify, which keeps the text as it is.
Can I format SVG, RSS or config files?
Yes. SVG, RSS, Atom, XSLT, XSD, Maven pom.xml, Android layouts and .NET .config files are all XML.
Why is my HTML page reported as invalid?
HTML is not XML: tags like <br> or <img> are never closed and attributes may be unquoted. Use the HTML formatter for HTML pages.
Is there a size limit?
Files up to 10 MB can be opened. Very large documents can take a moment to format.
Related tools
- JSON to XML Converter Convert JSON to XML and XML to JSON in your browser, with attributes, repeated elements and CDATA handled. Nothing is uploaded to a server.
- HTML Formatter Beautify messy HTML with clean indentation, or minify it safely, in your browser. Inline CSS and JavaScript are formatted too. Nothing is uploaded.
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.