XML Formatter & Validator

Loading the tool…

Make XML from an API, a SOAP response, a config file or a feed readable, or minify it to a single line. The tool also checks that the XML is well formed and points to the exact line and column of the first problem, with a short explanation, so you can fix it quickly.

Tip: the result updates as you type. Press Ctrl + Enter (Cmd + Enter on a Mac) to format large files.

How to use the XML Formatter & Validator

  1. Paste XML or open an .xml file.
  2. Choose Format or Minify, and the indent size for formatting.
  3. Read the result, or the error with its line and column if the XML is not well formed.
  4. Copy the result or save it as a file.

What is checked and how XML is formatted

Well-formedness
One root element, every tag closed in the right order, attribute values in quotes, no attribute repeated, and every & starting a valid entity such as & or ©.
Text is not changed
Text, CDATA sections and attribute values are written exactly as they are. Elements that mix text with child elements, and elements with xml:space="preserve", stay on one line so no spaces are added to their text.
Formatting
Each child element goes on its own line, indented by 2 or 4 spaces or a tab. Elements that contain only text stay on one line, such as <name>Amina</name>.
Minify
Removes the line breaks and indentation between elements. Comments are kept unless you turn off "Keep comments".

Examples

These outputs were produced by the same code that runs in the Tool tab.

Format a compact order

A one-line XML response, indented for reading.

Input

<?xml version="1.0" encoding="UTF-8"?><order id="ZV-1001" currency="AED"><customer><name>Amina Khan</name><city>Dubai</city></customer><items><item sku="SH-42" qty="1">Leather shoes</item><item sku="BT-07" qty="2">Belt</item></items><paid/></order>

Output

<?xml version="1.0" encoding="UTF-8"?>
<order id="ZV-1001" currency="AED">
  <customer>
    <name>Amina Khan</name>
    <city>Dubai</city>
  </customer>
  <items>
    <item sku="SH-42" qty="1">Leather shoes</item>
    <item sku="BT-07" qty="2">Belt</item>
  </items>
  <paid/>
</order>

Minify and remove comments

Line breaks, indentation and comments are removed.

Input

<config>
  <!-- production settings -->
  <server host="api.zvaad.com" port="443"/>
  <retries>3</retries>
</config>

Output

<config><server host="api.zvaad.com" port="443"/><retries>3</retries></config>
  • Removed 1 comment.

Mixed text is kept as it is

Text with inline tags is not split across lines.

Input

<note><to>Store team</to><body>Ship <b>today</b>, not <i>tomorrow</i>.</body></note>

Output

<note>
    <to>Store team</to>
    <body>Ship <b>today</b>, not <i>tomorrow</i>.</body>
</note>
  • Elements that mix text and child elements were kept on one line so their text is not changed.

Frequently asked questions

What does "well formed" mean?

The XML follows the basic syntax rules, so any XML parser can read it. It is different from being valid against a schema (XSD) or DTD, which also checks which elements and values are allowed.

Why is "&" an error?

In XML, & starts an entity such as &amp; or &lt;. A plain ampersand, as in "Khan & Sons", must be written as "Khan &amp; Sons".

Can it format SVG, XSLT or Android layout files?

Yes. They are XML, so they can be formatted and checked the same way.

Is my XML uploaded?

No. Formatting and checking run on your device.

Limitations and edge cases

  • XML is not validated against an XSD schema or DTD, and entities defined in a DOCTYPE are not expanded.
  • Only the first error is reported. Fix it, and the next one, if any, will be shown.
  • Attributes stay on the same line as their element, in their original order.

Read the privacy policy for how the site handles data.