Hunt
Skip to content

XML Formatter

Paste XML, a Maven pom.xml, a SOAP message, an RSS feed, an SVG or any other document, to indent it one element per line. The tool first checks that it's well-formed and points to the exact tag that breaks it. Comments, CDATA sections and the XML declaration are kept. Nothing is uploaded.

Runs in your browser

XML

Paste XML or press Sample

Formatted

Formatted XML will appear here

Well-formed XML

  • Every opening tag needs a closing tag (<a>…</a>) or must close itself (<a/>), and tags must close in the reverse order they opened.
  • A document has exactly one root element.
  • Attribute values must be quoted: id="1", not id=1.
  • < and & in text must be written &lt; and &amp;, or put in a CDATA section.

How to use the XML Formatter

  1. Paste XML, or press Sample.
  2. Fix any error: select its location to jump to it.
  3. Choose the indent, line width and whitespace handling.
  4. Copy the result or download it.

Examples

A minified document

Input
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101" lang="en"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book></catalog>
Output
<?xml version="1.0" encoding="UTF-8" ?>
<catalog>
  <book id="bk101" lang="en">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <price>44.95</price>
  </book>
</catalog>

A Maven dependency with 4-space indentation

Input
<project><modelVersion>4.0.0</modelVersion><dependencies><dependency><groupId>org.junit</groupId><artifactId>junit</artifactId><version>5.11.0</version><scope>test</scope></dependency></dependencies></project>
Output
<project>
    <modelVersion>4.0.0</modelVersion>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit</artifactId>
            <version>5.11.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Mismatched tags

Input
<order><item>Pen</order>
Output
</order> closes <item>, which is still open. Close <item> first.

The error points to line 1, column 17, where </order> is.

Whitespace in text

Reformat (the default) puts each element on its own line, which is right for data and configuration XML, where whitespace between elements doesn't matter. For documents mixing text and markup, such as XHTML or DocBook, choose Keep text spacing, which never adds or removes whitespace inside text.

Options

Indent
2 spaces (the default), 4 spaces or tabs.
Line width
Long tags wrap their attributes to stay within it.
Whitespace
Reformat (the default) or Keep text spacing, as described above.
Sort attributes
Order each element's attributes alphabetically, which makes diffs easier to read.

Limitations

  • The tool checks that XML is well-formed, not that it's valid against a DTD or XML Schema (XSD).
  • Entities declared in a DTD aren't expanded.

Frequently asked questions

Is my XML uploaded?

No. Checking and formatting run in your browser; nothing you paste is sent anywhere.

What's the difference between well-formed and valid?

Well-formed means the XML follows the syntax rules: nesting, quoting, one root. Valid means it also follows a schema (DTD or XSD) that says which elements and attributes are allowed. This tool checks the first.

Can it convert XML to JSON?

Not yet; XML to JSON is planned. For JSON, the JSON Formatter does the same job as this tool.