XML formatter

What is an Xml Formatter?

XML from APIs, SOAP services, RSS feeds, sitemaps and configuration exports often arrives as a single long line. The XML formatter indents elements according to their nesting so you can read the structure, compare documents and spot problems.

How to use it

  1. Paste the XML.
  2. Choose the indentation if options are available.
  3. Copy the formatted result.

Example

Input:

<order id='42'><customer>Asha</customer><items><item sku='A1' qty='2'/><item sku='B7' qty='1'/></items></order>

Output:

<order id='42'>
  <customer>Asha</customer>
  <items>
    <item sku='A1' qty='2'/>
    <item sku='B7' qty='1'/>
  </items>
</order>

Well-formedness rules

If formatting fails, the XML is probably not well-formed. Check that:

  • Every opening tag has a matching closing tag, or is self-closing.
  • Elements are properly nested: <a><b></a></b> is invalid.
  • There is exactly one root element.
  • Attribute values are quoted.
  • Special characters in text are escaped: &amp; for &, &lt; for <.
  • Tag names are case-sensitive: <Item> does not close with </item>.

Tips

  • Whitespace inside mixed-content elements can be significant; formatting may change how some documents are interpreted.
  • CDATA sections are kept as they are.
  • For data exchange, compare the XML with JSON using the XML to JSON converter.

Frequently Asked Questions

Why does my XML fail to format?

It is probably not well-formed, for example an unclosed tag, wrong nesting, an unquoted attribute or an unescaped ampersand.

Does formatting change the meaning of XML?

For data-oriented XML it does not. In mixed content, where text and elements are combined, whitespace can be significant.

How do I escape an ampersand in XML?

Use the predefined amp entity: an ampersand character followed by the letters amp and a semicolon. The same applies in text and attribute values.

Can I format SOAP messages and RSS feeds?

Yes. Any well-formed XML document can be formatted, including SOAP envelopes, RSS and Atom feeds, sitemaps, SVG files and Maven POM files.

Is my XML uploaded to a server?

No. Formatting runs entirely in your browser, so internal configuration files and API responses never leave your machine.

Can I minify XML instead of prettifying it?

Minifying removes the indentation and line breaks between elements to make the payload smaller. Keep pretty-printed XML for reading and reviews, and minified XML for transport.