About the XML formatter
XML is still everywhere: SOAP APIs, RSS feeds, sitemaps, SVG images, Android layouts, Maven and .NET project files. When it arrives on one line or with messy indentation, it's hard to read and debug.
This formatter indents XML into a clean tree, or minifies it to a single line. It also checks that the document is well-formed and points to the exact line and column of problems such as a missing closing tag.
How to use the XML formatter
- Paste your XML into the editor, open an .xml file, or click Load sample.
- Choose Format or Minify, the indentation, and whether to remove comments.
- Click Format XML or press Ctrl + Enter (Cmd + Enter on Mac).
- Fix any error it reports, then copy or download the result.
Example
Indent a one-line XML document
Input
<catalog><book id="1"><title>Dune</title><price currency="USD">9.99</price></book><!-- more books --></catalog>Output
<catalog>
<book id="1">
<title>Dune</title>
<price currency="USD">9.99</price>
</book>
<!-- more books -->
</catalog>Common errors and how to fix them
The element <note> is never closed. Add </note>.
An element has an opening tag but no closing tag. Add the closing tag, or write empty elements as <br/>.
The entity name must immediately follow the '&' in the entity reference
A bare & appears in text or an attribute, for example in a URL. Write it as &, or put the text in a <![CDATA[ ... ]]> section.
XML declaration allowed only at the start of the document
There is whitespace, a byte order mark or a second <?xml ... ?> before the declaration. The declaration must be the very first thing in the file.
Good to know
- Each element goes on its own line. Elements that contain only text stay on one line, like
<title>Midnight Rain</title>. - Text and inline tags mixed together, such as
<p>Some <b>bold</b> text</p>, are kept exactly as written, as is anything inside an element withxml:space="preserve", so formatting never changes your content. - Comments, CDATA sections, processing instructions and the DOCTYPE are kept. Entity references like
&are left as written. - It checks well-formedness: matching tags, a single root element, quoted and unique attributes, and that
&and<in text are escaped. It doesn't validate against a DTD or XSD schema.
Frequently asked questions
What does 'well-formed' mean?
A well-formed XML document follows XML's basic syntax rules, so any XML parser can read it: every tag is closed, tags are properly nested, there's one root element, and attribute values are quoted. Validity against a schema is a separate, stricter check.
Why is '&' an error?
In XML, & starts an entity reference such as <. A literal ampersand in text or an attribute must be written as &, and a literal < as <.
Can I format SVG, RSS or sitemap files?
Yes. They're all XML, so you can format, minify or check them here. Open the file with Open file or paste its contents.