XML Formatter

Paste XML to indent it neatly or squeeze it onto one line. It's checked as you type, with any error shown by line and column, and comments and CDATA stay as written.

Style
Indent

✓ Valid XML.

Formatted in your browser; your XML isn't uploaded, and external entities and links in it aren't fetched.

How to use it

  1. Paste XML or open a file: .xml, .svg, .rss, .kml, .xsd and similar.
  2. Choose Format with 2 or 4 spaces or tabs, or Minify.
  3. Copy the result or download it as formatted.xml. If the XML isn't well formed, the error shows the line with a ^ under the spot instead.

Common XML errors

  • Tags closed in the wrong order: <a><b></a></b>. Close the inner tag first.
  • A bare & or < in text: write &amp; and &lt;, or wrap the text in <![CDATA[ … ]]>.
  • Unquoted attribute: <item qty=2> must be <item qty="2">.
  • Two root elements: an XML document has exactly one outer element.
  • Case: <Item> and </item> are different tags in XML.

Example

The one-line feed loaded above becomes 16 indented lines: the comment stays as its own line, each <entry> and <tags> block opens and closes on separate lines, and <summary>First <b>bold</b> post</summary> stays on one line because it mixes text and a tag. The extra spaces in <entry id="2" status='draft'> are tidied, and the single quotes are kept.

The XML check uses the open-source fast-xml-parser (MIT licence). To turn XML into JSON, use the XML to JSON converter.

Frequently asked questions

Does it validate against an XSD schema or a DTD?

No. It checks that the XML is well formed: every tag closed and properly nested, attribute values quoted, one root element and no stray < or &. Checking against an XSD or DTD needs the schema file and a schema validator; well-formedness errors are the ones that stop any XML reader.

Why is some text left on one line?

An element that mixes text with tags, like <p>Hi <b>there</b></p>, is copied as written, because adding line breaks inside it would change its text. Elements that hold only text stay on one line too.

What is kept exactly as written?

Comments, CDATA sections, the <?xml ?> declaration, the DOCTYPE, attribute order and quotes, and entity references such as &amp;. Only the whitespace between tags changes; runs of spaces inside a tag become one space.

What does Minify remove?

The line breaks and indentation between tags and, unless you untick it, comments. Text inside elements is kept as it is.

Is my XML uploaded?

No. It's checked and formatted in your browser tab, and external entities or DTD links in it are never fetched.

More text and developer tools

See all text and developer tools →

Can't find the tool you need? Tell us, and the most requested tools get built first.