XML Formatter
Format and minify XML. Validate well-formedness with line and column on errors.
Enter input above to see the result.
What is this for?
XML remains ubiquitous in enterprise systems, configuration, data exchange, and markup—yet it arrives at your desk minified into an unreadable blob. This tool reformats XML into an indented tree for human reading, or strips whitespace for transport, whilst validating that the document is well-formed. The browser's native XML parser catches syntax errors and reports the line and column, saving you from hunting through thousands of characters by hand.
When to use it
- Inspecting a SOAP envelope or vendor XML config that arrived as a single minified line.
- Debugging generated XML before feeding it to a strict parser or validator.
- Pretty-printing an SVG or configuration file so you can actually read and edit it.
- Minifying well-formed XML to reduce file size before transmission or storage.
- Diffing two XML documents—format both, then compare their trees side by side.
- Verifying that hand-written XML doesn't have unclosed tags or broken nesting before committing.
How it works
- Paste or load XML. Feed the tool any XML snippet or document, complete or partial.
- Choose your mode. Select "Format" to pretty-print with configurable indentation (spaces or tabs, 2–8 character width), or "Minify" to strip all non-essential whitespace.
- Validate on parse. The browser's XML parser runs immediately. If the document is well-formed, output is generated; if malformed, an error message appears with line and column.
- Copy the result. Copy the formatted or minified XML to clipboard, or download it as a file.
Common gotchas
- Well-formed ≠ valid. This tool validates syntax only—balanced tags, quoted attributes, single root element. It does not check against a DTD or XML schema; that requires the schema file and a dedicated validator.
- Whitespace can be significant. By default, XML preserves all whitespace inside element text. Leading or trailing spaces in
<name> Alice </name>are part of the value. Re-indenting a whitespace-sensitive document (XHTML<pre>blocks, embedded code) will alter the data. - Self-closing vs explicit empty. The formatter normalises empty elements to self-closing form:
<br/>. This is correct in XML but differs from HTML, where<br></br>may be expected. If your parser is strict about this, manually adjust after formatting. - CDATA, comments, and processing instructions. These are preserved verbatim; their inner content is not re-indented. Embedded scripts or data blocks will not be reformatted.
- Attribute order may shift. XML parsers do not guarantee attribute order. If you rely on attribute sequence (e.g., for checksumming), canonicalise the document using XML C14N before comparison.
- Browser parser variance. Error messages and line/column reporting differ slightly between browsers. On some, only the error text may appear. Line and column extraction is best-effort.
Tips
- Use minify before sending XML over the network or embedding it in JSON or URLs.
- Use format + diff to compare two XML documents structurally, ignoring whitespace differences.
- If a large document fails to parse, the error location will help you isolate the problem. Fix the syntax, re-paste, and re-validate.