How to Format XML Online and Check It Is Well-Formed
Beautify or minify XML in your browser with a real well-formedness check. Learn why your text and pre blocks come back byte for byte.
Well-formed is not valid
These are two different questions and most tools blur them. Well-formed means the document is legal XML: one root element, legal names, quoted attribute values, no repeated attribute, matched tags, legal references. Valid means it satisfies a particular grammar — a DTD or an XSD — and that requires the schema, which this page does not fetch.
So the badge says Well-formed, and it means exactly that. A document can be well-formed and still be meaningless to the service that consumes it, and it can be perfectly valid against its schema while having a typo in a value that no schema will catch. When you need schema validation, use a validator; when you need to read the structure, this is the right tool.
1. Paste your XML
The box starts empty; Load sample puts a small document in it if you want a starting point. Nothing is pre-filled.
Minified and hand-indented documents both work. Whatever the input looks like, the output is laid out from the structure rather than from the whitespace you happened to paste, so an element indented with three spaces and one indented with none come out consistent.
2. Format or Minify
Format re-indents and Minify does the reverse, and both run the same check first, so switching between them can never change the verdict about your document. If the badge is not green, the output area is empty and Copy is disabled — a document that is not well-formed produces nothing to copy.
Pick an indent of 1, 2 or 4 spaces or a real tab. Comments are kept by default, because deleting them should be your decision; tick Strip comments when you want them gone, and note that it applies to the output only, never to your input.
Why your text is not re-wrapped
This is the behaviour that surprises people, so it is worth stating plainly. Only whitespace between elements is rewritten, and only inside elements whose children are all elements. Anything holding text — a paragraph with a bold word in it, a pre block, a CDATA section, an attribute value — comes out byte for byte.
The reason is that in those elements the whitespace is the data. Reflowing Hello <b>world</b> into Hello<b>world</b> or breaking a line inside a pre block changes what the document says, and a formatter that changes meaning while claiming to clean up is worse than no formatter. The visible consequence is that a document that is mostly text may look barely different afterwards, and that is correct behaviour rather than a failure.
What the check catches
A second root element, an unquoted attribute value, the same attribute twice, a tag that closes the wrong element, an element or attribute name starting with a digit, an undeclared entity, text sitting outside the root, an unterminated comment or CDATA section, and a DOCTYPE with an unclosed internal subset. Errors report a line and a column, so you can go straight to the spot rather than hunting through the document.
Quoted attribute values are read as single units, which is why a > inside an attribute does not end the tag early. Namespace prefixes, default namespaces, processing instructions, CDATA sections and DOCTYPE internal subsets that declare entities are all handled. What is not done is resolving a namespace prefix to a URI or fetching an external DTD, so a document that depends on a schema for its meaning is checked for structure only.
Caps and privacy
Three limits are checked before any work starts: 200,000 characters of input, 200 levels of element nesting, and 400,000 characters of output. Deeply nested input is refused quickly rather than attempted — a 23,250-level document is a few tens of kilobytes but is a runaway for anything that recurses, which is why the nesting limit exists at all.
Parsing happens in this tab and nothing is uploaded. That is worth having in mind for the documents people actually paste here: SOAP responses, SVG from an internal service, Maven or Android manifests, an exported feed. Keep the source file anyway, so you can compare.
Try it free — XML Formatter & Well-Formness Check
Beautify or minify XML with a real well-formedness check: one root element, quoted attributes, no duplicates, matched tags and legal entity references, with the line and column of any problem. Text, pre blocks and CDATA are reproduced byte for byte, and both modes reach the same verdict.
Open XML Formatter & Well-Formness Check