Skip to content
Back

XML Formatter

Format, validate and minify XML, with errors pointed out by line and column.

Pretty-print, check and minify XML in your browser

XML Formatter takes XML that arrives on one long line or with messy indentation and lays it out with one element per line, indented by nesting depth. It also checks that the XML is well-formed and, if it isn’t, shows the error your browser’s XML parser reports, with the line and column where it found the problem.

The reverse is there too: Minify removes the whitespace between tags to make the file smaller. The XML stays on your device — it’s read and formatted in the page, not uploaded — and inputs up to 5 MB are accepted.

How to format or validate XML

  1. Paste your XML into the input box, or click Load an example to try the tool first.
  2. The formatted result appears below as soon as you stop typing.
  3. Choose an indent of 2 spaces, 4 spaces or tabs.
  4. Tick Minify for a single-line version, or tick “Write empty elements as <a/>” to shorten elements that have no content.
  5. If an error appears under the input, fix the spot it names; the result updates by itself once the XML is well-formed.
  6. Click Copy result, or Download .xml to save it as formatted.xml (or minified.xml).

What changes and what stays exactly as written

  • Changed: the line breaks and indentation between tags, and the spacing inside tags — attributes end up separated by single spaces with no spaces around the equals sign.
  • Unchanged: attribute values (with their original quotes), text, entity references such as &amp;, comments, CDATA sections, processing instructions, the XML declaration and the DOCTYPE, including an internal subset.
  • Mixed content: an element that holds both text and child elements, such as <p>Hello <b>world</b></p>, is kept on one line as written, because adding line breaks there would change the text.
  • Text-only elements: stay on one line with their text untouched, including any spaces inside.
  • xml:space="preserve": elements with this attribute are left exactly as they are.

When a formatter helps

  • Reading API responses and feeds: turn a one-line SOAP response, RSS feed or sitemap into something you can scan.
  • Finding a syntax error: a missing closing tag or an unescaped & is reported with its line and column.
  • Cleaning up config files: consistent indentation for Android layouts, Maven POMs, SVG files or app settings before you commit them.
  • Shrinking a file: minify XML you send over the network or embed in another file.

Tips for well-formed XML

  • Escape ampersands and angle brackets: a bare & or < in text breaks the document; write &amp; and &lt;, or wrap the text in a CDATA section. The HTML Entity Encoder / Decoder can escape a snippet for you.
  • One root element: everything except the declaration, comments, processing instructions and the DOCTYPE must sit inside a single top-level element.
  • Names are case-sensitive: <Item> must be closed with </Item>, not </item>.
  • Working with JSON as well? the JSON Formatter does the same job for JSON.

Well-formed versus valid

What the check covers

Well-formed means the XML follows the basic syntax rules: tags are properly nested and closed, attribute values are quoted, and special characters are escaped. That is what this tool checks, using the XML parser built into your browser.

Valid is a stronger claim: that the document also matches a schema or DTD describing which elements and attributes are allowed. This tool doesn’t validate against schemas, and it doesn’t fetch external DTDs.

Why error messages differ between browsers

Chrome, Firefox and Safari each use their own XML parser, so the wording of the message, and sometimes the exact column, varies. The line number is usually the most reliable clue; the real mistake is often just before the position reported.

XML Formatter: common questions

Is my XML uploaded anywhere?

No. Checking and formatting both happen in your browser, and nothing is stored after you close the page.

Why is there no result when my XML has an error?

Formatting broken XML could hide or move the problem, so the tool only formats input the browser’s XML parser accepts. Fix the error shown under the input and the result appears.

Does minifying change my data?

Minify only removes whitespace-only text between tags. Text content, CDATA, comments and whitespace inside mixed-content or xml:space="preserve" elements are kept, because that whitespace can be meaningful.

What is the size limit?

Inputs up to 5 MB. Larger files are refused with a message rather than slowing the page down; very large files are also reformatted only after you pause typing.

Can it format HTML?

Only HTML written as well-formed XHTML. Ordinary HTML allows unclosed tags such as <br> and <li>, which an XML parser rejects. To shrink HTML, use the HTML Minifier; more developer tools are listed in the category.