XML Formatter and Validator
Format and validate XML with real indentation, precise error locations, and CDATA and comments preserved exactly.
Keep XML comments in the output. Uncheck to drop them.
Order each element's attributes by name for diff-friendly output.
xml:space="preserve" elements, whitespace is data, not formatting — so reindenting can change meaning. This formatter treats whitespace as formatting in exactly two places: whitespace-only text between elements is dropped, and the leading/trailing whitespace of each text run is trimmed. It does not honor xml:space="preserve". Text that must keep its exact whitespace should be wrapped in <![CDATA[…]]>, which this formatter preserves verbatim.How it works
- Type or paste the XML you want to reformat.
- Pick Format (indent and align) or Minify (strip insignificant whitespace); the result updates as you type, in your browser.
- Copy the result or download it as an .xml file.
Frequently Asked Questions
How is the XML parsed?
With a purpose-built tokenizer, not a regular expression. XML is recursive, so a regex cannot tell whether a "<" opens a tag, sits inside a CDATA section, or is escaped — which is how malformed input becomes silently wrong output.
What does it tell me when the XML is broken?
The line and column where parsing stopped, plus what was wrong: a mismatched closing tag naming both sides, an unquoted attribute value, a duplicate attribute, text outside the root element, or an unterminated comment or CDATA section.
Are DTDs and external entities processed?
No. A DOCTYPE is preserved as text but never resolved, and no external file or URL is ever fetched. That also means the classic XXE and billion-laughs attacks have no surface here.
Will formatting change my data?
No. CDATA sections are preserved verbatim, comments are kept unless you turn them off, and the XML declaration is reproduced exactly as you wrote it so a declared encoding is never silently altered. Formatting twice produces identical output.