XML Formatter

Pretty-print XML with 2 spaces, 4 spaces or tabs. The input is checked for well-formedness first, so errors are reported with line and column.

Output

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is XML Formatter?

The XML Formatter re-indents XML so every element starts on its own line with consistent indentation. Elements that only contain text stay on one line. Before formatting, the document is checked for well-formedness, and problems such as mismatched tags are reported with their position.

How to use XML Formatter

  1. Paste the XML into the input box or click Load sample.
  2. Choose the Indentation (2 spaces, 4 spaces or Tab).
  3. Click Format; the output also updates while you type.
  4. Copy or download the formatted XML.

Example

Input
<a><b x="1">t</b><c/></a>
Output
<a>
  <b x="1">t</b>
  <c/>
</a>

When to use XML Formatter

Use it to read SOAP responses, sitemaps, RSS feeds, Android layouts or Maven POM files. Be careful with mixed content (text and tags interleaved, as in XHTML paragraphs): adding line breaks there can change whitespace that matters. It does not validate against a DTD or XSD.

How XML Formatter works

The input is first validated with the XMLValidator of fast-xml-parser, which checks tag nesting, attribute syntax and closing tags and reports a line and column. Valid documents are then formatted with the xml-formatter library: each element, comment and processing instruction is put on its own line with the chosen indentation, and text-only elements are collapsed onto one line (<b x="1">t</b>). Attribute values, CDATA and comments are kept.

Common Use Cases

  • Reading a minified SOAP or REST XML response
  • Cleaning up sitemap.xml or RSS feeds
  • Reviewing Android or .NET XML config files
  • Finding the tag that breaks an XML document

Security Note

Everything runs locally in your browser; the code you paste is not uploaded.

FAQs

Does it validate against an XSD schema?

No. It only checks that the XML is well-formed (correct nesting and syntax).

Are comments and CDATA kept?

Yes, they are preserved in the output.

Why was my document rejected?

The error message gives the line and column, for example a closing tag that does not match the open one.

Explore more categories