Skip to content

XML Formatter & Beautifier

Turn compressed or messy XML into a cleanly indented document that is easy to read and review.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is XML Formatter & Beautifier?

XML is used for configuration files, RSS and Atom feeds, SVG, SOAP messages, Office documents and many enterprise formats. It often arrives on a single line or with inconsistent indentation, which hides the structure.

This formatter first checks that the document is well-formed, then re-indents it. It keeps the XML declaration, attributes, comments and CDATA sections, and it leaves mixed content such as <p>Hello <b>world</b></p> untouched because whitespace is meaningful there. Entities are never expanded or fetched, so even hostile documents are safe to paste.

How does it work?

  1. Paste your XML or open an .xml file.
  2. Choose 2 spaces, 4 spaces or a tab, and decide whether to keep comments.
  3. If the XML is not well-formed, read the error message: it includes the line and column.
  4. Copy the result or download formatted.xml.

Common use cases

  • Reading a SOAP response or an RSS feed returned on one line.
  • Cleaning a pom.xml, web.config or Android layout before committing it.
  • Making an XML export from an ERP or CMS reviewable in a diff.
  • Checking the nesting of a hand-written XML snippet.

Examples

Try this input in the tool above:

Input
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price currency="USD">44.95</price></book><!-- next entry --><book id="bk102"><author>Ralls, Kim</author><title>Midnight Rain</title><price currency="USD">5.95</price></book></catalog>
Output
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <price currency="USD">44.95</price>
  </book>
  <!-- next entry -->
  <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <price currency="USD">5.95</price>
  </book>
</catalog>

Privacy

XML Formatter & Beautifier runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Only whitespace between elements is changed, but formatting can still alter documents where whitespace is significant (xml:space="preserve", pre-formatted text inside text-only elements). DTD validation is not performed.

Frequently asked questions

Does the formatter change my data?

No. Element names, attributes, comments, CDATA and text are kept. Only the whitespace between elements is normalised. Mixed content is preserved exactly.

What happens with a DOCTYPE that declares entities?

The document is formatted, but entities are never expanded and a warning explains the “billion laughs” and XXE risk of such documents.

Why does it refuse my XML?

The document must be well-formed: one root element, properly nested and closed tags, quoted attribute values. The error message shows the line and column of the first problem.

More tools in JSON & Data →