Practical guide

How to format XML and check that it is well-formed

Use a browser-local workflow to pretty-print XML, minify it, and distinguish well-formedness checks from schema validation.

Well-formed is not the same as schema-valid

XML is well-formed when its markup follows XML syntax, including one document element and correctly nested tags. A well-formed document can still violate an XSD or the rules of an application. The browser tool checks parsing only; it does not load or evaluate a schema. See the W3C XML 1.0 specification for the document and well-formedness rules.

Format a minified document

Open the [XML Formatter & Validator](/tools/xml-formatter/), paste a small XML document, and choose two spaces, four spaces, or tabs. Select Format XML. Element-only sections are indented. Mixed text-and-element sections are kept inline to avoid inserting line breaks into their text. Compare the output with the original before replacing a file.

Minify or check well-formedness

Select Minify XML to remove formatting whitespace between child elements while keeping mixed-content text. Select Check well-formedness to ask the browser's native XML parser to read the document and report its root element and element count. A parsing error means you should inspect the reported line and column where your browser provides them, then correct the source and try again.

Keep whitespace and serialization changes in mind

The XML Serializer may normalize namespace prefixes or entity spellings. Whitespace-only nodes between child elements may be removed unless xml:space="preserve" is set. Do not use the result for signed XML, canonicalization, or byte-sensitive comparisons. DTDs and custom entity declarations are rejected; use a trusted, schema-aware XML tool if you need DTD or XSD validation.

Example and limits

For example, paste <catalog><item id="001"><name>Green tea</name></item></catalog> and format it to inspect the nesting. The quoted identifier stays quoted in the XML text. This tool does not infer data meaning, validate schemas, or upload the document. For how the browser parses XML, see MDN's DOMParser guide.

Try XML Formatter & Validator →