XML Formatter
Format, minify and validate XML with configurable indentation.
Indent Size
What the XML Formatter does
This tool takes raw or minified XML and pretty-prints it with consistent indentation so the nesting of elements is easy to read. It can also do the opposite, minifying XML by stripping the whitespace between tags, and it can validate that your markup is well-formed before you rely on it.
It is handy for developers and integrators working with configuration files, SOAP or REST payloads, RSS and sitemap feeds, SVG, and any other XML-based format. Cleanly formatted XML makes it far easier to spot a missing tag, a misplaced attribute, or an unexpected nesting level.
How to use it
Choose an indent size of 2 or 4 spaces, then paste your XML into the input box. Click Format XML to produce the indented version, Minify to collapse it onto as few characters as possible, or Validate to simply check whether the document is well-formed. The result appears in the output area, and Copy Output puts it on your clipboard.
If the XML contains a syntax problem, such as an unclosed tag or a stray character, the tool shows the parser's error message instead of malformed output, so you can locate and fix the issue quickly.
How it works and what it preserves
Formatting is powered by the browser's native DOMParser and XMLSerializer, the same XML engine the browser itself uses, so the parsing rules are standards-based. The formatter walks the parsed document tree and rebuilds it with your chosen indentation, keeping attributes, comments, and CDATA sections intact, and preserving the XML declaration when your input starts with one.
Elements that contain only short text are kept on a single line for readability, while elements with child nodes are expanded across multiple indented lines. Because the tool reformats a parsed tree rather than just shuffling text, the output is always well-formed XML equivalent to your input.