XML Formatter
Indent and tidy XML, or collapse it to one line.
Well-formed XML. Comments and CDATA were preserved.
About this tool
Re-indent XML so its structure is readable, or strip it back to a single line. Malformed markup is reported with the parser's own message rather than being silently mangled.
How to use it
- Paste your XML — a document, an RSS feed or a SOAP envelope.
- Pick an indent width, or choose Minify.
- Copy or download the tidied result.
Well-formed is not the same as valid
These two words get used interchangeably and mean quite different things.
Well-formed means the document follows XML's syntax rules: one root element, every tag closed, tags properly nested, attributes quoted, special characters escaped. This is a purely structural question and it is what this tool checks.
Valid means the document also matches a schema — a DTD, XSD or RelaxNG — which defines which elements are allowed, in what order, with which attributes and data types.
A document can easily be well-formed and completely wrong for its purpose. <invoice><banana/></invoice> is perfect XML and meaningless as an invoice. Checking against a schema needs the schema, which is why validators that do it ask you to upload one.
What gets preserved when reformatting
A formatter that silently rewrites your document is worse than no formatter. This one is deliberately conservative.
Preserved exactly: CDATA sections, comments, processing instructions, the XML declaration, attribute quoting style, and entity references. Only whitespace between elements changes.
CDATA matters most. A <![CDATA[...]]> block exists precisely to hold content that would otherwise need escaping — embedded HTML, scripts, raw text with angle brackets. Reformatting its contents would change its meaning, so it is passed through untouched.
Whitespace inside elements is significant in some formats. Mixed content — text and elements in the same parent, as in XHTML — can change meaning when re-indented. If your document is document-oriented rather than data-oriented, check the result before committing it.
Frequently asked questions
- Does it validate against a schema?
- No. It checks that the document is well-formed — tags balanced and properly nested — but does not validate against a DTD or XSD.
- Will it preserve CDATA sections and comments?
- Yes. CDATA blocks, comments and processing instructions are kept intact and re-indented along with the rest of the document.
- Where is my XML processed?
- Entirely in your browser. SOAP envelopes and API responses often contain customer data, so nothing is uploaded and no copy is retained after you close the tab.