XML Formatter & Validator

Indent XML so the element hierarchy is readable, and check that the document is well-formed. Errors are reported with line and column.

Loading tool…

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

  1. Paste XML or open an .xml, .svg, .rss or .xsd file.
  2. Pick 2 spaces, 4 spaces or Tab.
  3. Fix any well-formedness error at the reported line.
  4. Copy the formatted XML or download it.

Frequently asked questions

What is the difference between well-formed and valid XML?
Well-formed XML follows the syntax rules (nesting, quoting, escaping). Valid XML is also well-formed and conforms to a DTD or XML Schema. This tool checks well-formedness; schema validation needs the schema file and a validating parser such as xmllint.
Why do I get an error about &amp; in my XML?
A bare & starts an entity reference. Write it as &amp;, or put the text in a <![CDATA[ … ]]> section. The same applies to < in text.
Will formatting change my data?
Element names, attributes, CDATA and comments are kept. Leading and trailing whitespace inside text nodes is trimmed and indentation is added, which matters only for whitespace-sensitive documents.

Related tools