Skip to main content
ToolsBay

XML Beautifier

Format, minify and check XML without mangling CDATA or attributes.

Runs entirely in your browser — nothing is uploaded

Your XML

1 line

Formatted

1 line

Frequently asked questions

Will formatting change what my XML means?

No. Attribute values, CDATA sections and anything inside xml:space="preserve" are copied through untouched, and only whitespace between elements is altered. Formatting then minifying returns the document you started with.

Why do some tools break XML containing a ">" in an attribute?

Because they look for the next ">" character to find the end of a tag. In <a title="x > y"> that lands in the middle of the attribute and cuts the tag in half. This tool tracks quoting, so the attribute survives.

Does it validate against my schema?

No. It checks well-formedness — tags matched and nested correctly, one root element, comments and CDATA terminated. Whether the document satisfies an XSD or DTD is a separate question this does not answer.

What happens to comments?

They are kept when formatting, unless you turn them off, and removed when minifying since that is the point of minifying.

Reading XML that arrived as one line

XML from an API, a SOAP envelope, an RSS feed or a build artefact usually comes with every line break stripped. The structure is all still there, just invisible. Re-indenting it makes the nesting legible again, which is normally the whole reason you opened the file.

The parts that must not be touched

Formatting XML looks like a whitespace problem and is really a parsing problem. Three regions carry meaning that reindenting would destroy:

  • Attribute values<a title="x > y"> contains a > that does not end the tag.
  • CDATA sections — everything between <![CDATA[ and ]]> is literal, including markup and spacing.
  • xml:space="preserve" — an explicit instruction that whitespace inside this element is content, not layout.

This tool tokenises the document before touching it, so all three survive. A formatter built on regular expressions typically mangles at least one.

Mixed content and minification

Minifying removes whitespace between tags, but not whitespace beside text. In <p>Hello <b>there</b></p> that space is part of the sentence; deleting it would render “Hellothere”. Distinguishing the two cases is the difference between a minifier you can trust on documents and one that only works on machine-generated data.

To turn XML into JSON, use XML to JSON, and for the reverse JSON to XML. For a sitemap specifically the XML sitemap generator produces the exact format search engines expect. For HTML rather than XML, use the HTML beautifier.

All developer tools