XML Formatter & Validator
Format, validate, and pretty-print XML with proper indentation and error detection.
How to Use
- Paste your XML into the input box.
- Click "Format" for pretty-printed, indented output.
- Click "Minify" to collapse it to a single line.
- Click "Validate Only" to check well-formedness without reformatting.
When to Use This
- Reading a SOAP envelope or SAML assertion captured from a network trace, where the whole document arrives as one unbroken line.
- Checking an RSS feed or sitemap before upload, since an unescaped ampersand in a title is a common cause of silent rejection.
- Shrinking a configuration document for an application that reads its XML from a single-line environment variable or a database column.
- Comparing two versions of a build file by formatting both first, so the diff shows real changes rather than indentation noise.
Frequently Asked Questions
About This Tool
XML has two separate standards of correctness. Well-formedness is the syntax layer: one root element, every tag closed, tags nested rather than overlapped, attribute values quoted, and the reserved characters escaped. Validity is the stronger claim that a document also matches a DTD or XSD saying which elements may appear where. A file can be perfectly well-formed and still be meaningless to the system that will consume it.
This tool runs your text through the browser's DOMParser in application/xml mode and looks for the parsererror node that parsers insert on failure, so the message you read is the browser's own. Formatting then works on the original string rather than the parsed tree: tags are split out with a regular expression and re-emitted with two-space indentation, which keeps attribute order and spelling exactly as you wrote them. Minify collapses the whitespace sitting between tags.
Notes & Limits
- The formatter re-indents the raw text rather than the parsed document, so a CDATA section or comment containing a greater-than character can be split in the wrong place.
- Whitespace between tags is removed before indenting. In mixed content, or where xml:space is set to preserve, that changes what the document means.
- A DOCTYPE with an internal subset is treated as ordinary text by the indenter, so a declaration spanning several lines can come back reflowed oddly.
- Error text comes from the browser's own parser, so the wording and the position reported differ between Chrome, Firefox and Safari for the same file.