Skip to content
Free developer tool

XML formatter

This XML formatter checks that XML is well-formed, then indents it so the structure is easy to read, or squeezes it onto one line. Developers use it for API responses, config files, RSS feeds and SOAP messages.

  • Runs in your browser
  • Free, no account needed
  • Copy or download the result
Private: runs on this device

Input

253 characters

Result

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <!-- Two books -->
  <book id="b1" lang="en">
    <title>XML Basics</title>
    <price currency="USD">29.99</price>
  </book>
  <book id="b2">
    <title>Tea &amp; Code</title>
    <note><![CDATA[Use <b> tags]]></note>
  </book>
</catalog>

Example

Input
<?xml version="1.0" encoding="UTF-8"?><catalog><!-- Two books --><book id="b1" lang="en"><title>XML Basics</title><price currency="USD">29.99</price></book><book id="b2"><title>Tea &amp; Code</title><note><![CDATA[Use <b> tags]]></note></book></catalog>
Result
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <!-- Two books -->
  <book id="b1" lang="en">
    <title>XML Basics</title>
    <price currency="USD">29.99</price>
  </book>
  <book id="b2">
    <title>Tea &amp; Code</title>
    <note><![CDATA[Use <b> tags]]></note>
  </book>
</catalog>

How to use the xml formatter

  1. Paste your XML into the XML box.
  2. Choose an Output: Pretty with 2 spaces, 4 spaces or tabs, or Minify.
  3. Choose whether to keep or remove Comments.
  4. Press Run, then Copy result or Download.

How it works

The check follows XML 1.0 well-formedness rules: one root element, matching start and end tags, quoted and unique attributes, valid names, and an & only as the start of a reference.

The first problem stops the check and is reported with its line and column.

Entities are never expanded. &amp;, &lt;, &gt;, &quot;, &apos; and numeric references are always allowed, and other named entities are allowed only when the document has a DOCTYPE.

Whitespace-only text between elements is removed. An element that contains text keeps its content exactly as written, with no indentation added inside it, and xml:space="preserve" content is left untouched.

Comments, CDATA sections, processing instructions and the DOCTYPE pass through unchanged. The DTD is not used to validate the document.

Everything runs in your browser. Your input is not uploaded or stored.

Questions and answers

What is the difference between well-formed and valid XML?

Well-formed XML follows the basic syntax rules, such as matching tags and quoted attributes. Valid XML also matches a schema or DTD, which this tool does not check.

Why does it say an entity is not defined?

Without a DOCTYPE, XML only knows &amp;, &lt;, &gt;, &quot; and &apos;. Write a plain & as &amp;, or use a numeric reference such as &#169;.

Does formatting change my data?

Both modes remove whitespace-only text between elements, which most programs ignore. Text inside elements is kept as written. If that whitespace matters, mark the element with xml:space="preserve".

Is my XML uploaded?

No. It runs in your browser, and nothing you paste is sent to a server.

All 220 SnowRock tools