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.
<?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.
Fix the highlighted fields to update the output.
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
- Paste the XML. A feed, a sitemap, a WordPress export or a config file all work.
- Pick format or minify. Format indents by nesting depth; minify drops the whitespace between elements and nothing else.
- Choose the indent. Two spaces, four spaces or tabs.
- Read the error if one appears. It names the line, the column and what was expected, rather than saying the document is invalid.
- 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<and&, 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
xmlnschanges 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?
Will it fix my XML?
Is HTML supported?
&, none of which are valid XML.Are my namespaces safe?
xmlns attributes are copied exactly, since changing them changes the meaning of every name in the document.