About the XML Formatter
The formatter first checks the document with the browser's native XML parser (DOMParser with application/xml), which enforces XML 1.0 well-formedness: one root element, matching and properly nested tags, quoted attributes, escaped & and < in text, and no duplicate attributes. If it fails, you get the parser's message with its line and column, for example Opening and ending tag mismatch.
Pretty-printing uses a tokenizer that understands CDATA sections, comments, processing instructions such as <?xml-stylesheet?>, DOCTYPE declarations with internal subsets, and attribute values that contain >. Each element goes on its own line; an element that only holds short text stays on one line, like <loc>https://example.com/</loc>. Attributes and namespace prefixes are kept exactly as written.
One caveat: whitespace-only text between tags is replaced by the new indentation and text content is trimmed. That is fine for configuration, SOAP, RSS, sitemaps and Maven POMs, but not for documents where whitespace is meaningful (xml:space="preserve", mixed content in DocBook or XHTML). Validation checks well-formedness only, not a DTD or XSD schema. All processing happens in your browser.
How to use it
- Paste XML or open an .xml, .svg, .rss or .xsd file.
- Pick 2 spaces, 4 spaces or Tab.
- Fix any well-formedness error at the reported line.
- Copy the formatted XML or download it.
Frequently asked questions
What is the difference between well-formed and valid XML?
Why do I get an error about & in my XML?
& starts an entity reference. Write it as &, or put the text in a <![CDATA[ … ]]> section. The same applies to < in text.