ποΈ XML Formatter & Validator
Pretty-print, minify, and validate XML with precise error locations.
How to Use This Tool
Paste XML, choose pretty-print or minify, and get formatted output plus validation. Malformed documents produce an error message naming the exact line and character where parsing failed. All processing happens in your browser.
Paste XML into the input box.
Pick pretty-print for reading or minify for production.
Click Format and Validate, then copy the output.
What Validation Checks
The parser enforces XML well-formedness: exactly one root element, properly nested and closed tags, quoted attribute values, no overlapping elements, and correct entity usage. It reports the precise line and column of the first error, which is usually where the real mistake is. Note this checks syntax (well-formedness), not validity against a schema or DTD; a document can be well-formed but still violate your application's rules.
Common XML Errors
Unescaped ampersands and angle brackets cause most failures: write & for &, < for <, and > for >. Attribute values must always be quoted. And remember XML is case-sensitive: <Book> and <book> are different elements.
Pretty Print vs Minify
Pretty-printing puts each element on its own line with consistent indentation, making structure scannable for debugging configs, SOAP messages, and feeds. Minifying strips all insignificant whitespace for the smallest payload, ideal for production APIs. Both preserve comments, CDATA sections, and processing instructions exactly.
Worked Example
Paste <catalog><book id="1"><title>X</title></book></catalog> and pretty-print with 4 spaces: each nested element indents one level, attributes stay on the opening tag, and the output is immediately readable. Introduce a typo like </bok> and the validator reports the exact line, saving a hunt through the file.
Where XML Still Matters
Despite JSON's dominance, XML remains entrenched in enterprise SOAP services, RSS/Atom feeds, SVG graphics, Office documents (.docx is zipped XML), Android layouts, and Maven/Gradle configs. Knowing how to quickly format and validate it is a durable skill.
Frequently Asked Questions
How do I format XML online?
Paste your XML into this tool and click Format and Validate. It pretty-prints with your chosen indent, or minifies to a single line. Malformed XML gets a precise error location instead.
What is the difference between well-formed and valid XML?
Well-formed means correct syntax: one root, closed tags, quoted attributes. Valid means it also conforms to a schema (XSD/DTD). This tool checks well-formedness, which catches the vast majority of real errors.
Why does my XML fail to parse?
The top causes are unescaped & and < characters, mismatched tag case, unclosed tags, and multiple root elements. The validator pinpoints the exact line and character.
Should I minify XML for production?
Yes if payload size matters. Minifying strips insignificant whitespace, which can shrink config-like XML by 20 to 40 percent. Keep pretty-printed copies for debugging.
Does it preserve CDATA and comments?
Yes. CDATA sections, comments, and processing instructions pass through untouched in both pretty-print and minify modes.