XML Formatter & Validator

Indent or minify XML and check it is well formed, with the line and column of any problem. Comments, CDATA and mixed content are left as they were.

Enable JavaScript to customise; default output below.

Nothing is uploaded. The parsing happens in this tab.

Mode

format indents by nesting; minify removes the whitespace between elements.

Indent
More options Show
Live preview formatted.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>BucketWP</title>
    <item>
      <title>Hello world</title>
      <guid isPermaLink="false">1</guid>
      <description><![CDATA[<p>Rich text stays as it is.</p>]]></description>
    </item>
    <!-- one more item goes here -->
  </channel>
</rss>

Output is valid and updates as you type.

Indent XML, minify it, or find out exactly where it stops being well formed. Comments, CDATA and mixed content come out as they went in.

How to use

  1. Paste the XML. A feed, a sitemap, a WordPress export or a config file all work.
  2. Pick format or minify. Format indents by nesting depth; minify drops the whitespace between elements and nothing else.
  3. Choose the indent. Two spaces, four spaces or tabs.
  4. Read the error if one appears. It names the line, the column and what was expected, rather than saying the document is invalid.
  5. Copy or download the result. The declaration, comments and CDATA sections are untouched.

Example

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><title>BucketWP</title><item><guid isPermaLink="false">1</guid></item></channel></rss>

comes out as

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>BucketWP</title>
    <item>
      <guid isPermaLink="false">1</guid>
    </item>
  </channel>
</rss>

An element holding only text stays on one line, because breaking it would add whitespace to the text.

Pitfalls

  • Indenting mixed content changes it. <p>Some <b>bold</b> text</p> keeps its single spaces here; a formatter that reindents it has edited your sentence.
  • XML is case sensitive, so <Item> and </item> do not match. That is the most common error this reports.
  • Every attribute value needs quotes. <a href=x> is fine in HTML and invalid in XML.
  • A document has exactly one root element. Several siblings at the top level is a fragment, which needs the single root check turned off.
  • A bare < or & in text is an error. Write them as &lt; and &amp;, or wrap the value in CDATA.
  • CDATA is not a comment. Its contents are text, and the formatter leaves them alone, including any indentation inside.
  • Minifying removes whitespace between elements but keeps it inside text, so a value with meaningful spaces survives.
  • Namespaces are attributes as far as formatting goes. Prefixes are kept exactly as written, since xmlns changes what the names mean.

Compatibility

The output is XML 1.0. Comments, CDATA, processing instructions and internal declarations are preserved verbatim, so an XML declaration with an encoding stays at the top where parsers look for it. Attribute quote characters are kept as you wrote them. The tool runs in any browser from 2017 onwards and uploads nothing.

Frequently asked questions

Does it validate against a schema?
No. It checks the document is well formed, which is the structural half. A DTD or XSD check needs the schema and a validator that reads it.
Will it fix my XML?
No. It reports the first problem with a position, and leaves the fixing to you. Silent repairs hide data loss.
Is HTML supported?
Only if it is XHTML. HTML allows unquoted attributes, unclosed tags and bare &, none of which are valid XML.
Are my namespaces safe?
Yes. Prefixes and xmlns attributes are copied exactly, since changing them changes the meaning of every name in the document.
How large a file can it take?
The field holds up to 100,000 characters. Larger documents belong in a script rather than a browser tab.
Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.