XML Formatter
Pretty-print and indent messy XML.
How to use XML Formatter
What this tool does
This tool cleans up XML. Format mode re-indents a document so its structure
is easy to read — useful when XML arrives as one long line or with inconsistent
spacing. Minify mode does the reverse, stripping the insignificant
whitespace between tags to produce the smallest valid output. Both modes start
by parsing the XML with the browser’s native DOMParser, so malformed input is
caught before anything is produced. Everything runs on your device; the XML you
paste is never uploaded.
Why you might need it
XML configuration files, SOAP responses, RSS feeds, sitemaps, and build descriptors are often generated by machines and shipped without any formatting — a single unreadable line, or indentation that does not match the nesting. To review a diff, debug a response, or simply understand the structure, you need it laid out cleanly. Minification solves the opposite problem: when XML is sent over a network or embedded in another document, the whitespace is wasted bytes.
How to use it
- Paste your XML into the input box, or drop an
.xmlfile onto it. - Choose Format to pretty-print, or Minify to compact.
- For Format, pick an indentation width: 2 spaces, 4 spaces, or tab.
- Click the action button, or press Ctrl/Cmd + Enter.
- Copy the result with one click. The character counter shows how much minifying saved.
How it works
Rather than reformatting the raw text with string tricks, the tool parses the
XML into a real document tree and then walks that tree to produce output. This
means the result is always well-formed: tags are balanced, attributes are
escaped, and nesting is correct. When formatting, an element whose only content
is text — like <title>Hello</title> — is kept on a single line, while
elements with child elements are expanded with each child on its own indented
line. Empty elements collapse to the self-closing form <tag/>. Minifying joins
everything back together with no whitespace between tags, while still preserving
meaningful text content.
Common pitfalls
The most important thing to know is that whitespace inside an element can be
significant in XML, and a formatter cannot always tell. When an element contains
only text, this tool trims and normalises that text — which is the right choice
almost always, but if you rely on exact leading or trailing spaces inside a
text-only element, formatting will change them. Mixed content (text interleaved
with child elements) has its text segments placed on their own lines, which can
shift meaning in rare document-style XML. If your input fails to parse, look for
unclosed or mismatched tags, or unescaped < and & characters in text — those
are the usual causes of a malformed document.
Tips and advanced use
Use Minify before sending XML across a network or storing it, then Format again whenever you need to inspect it — the two are reversible in terms of meaning. When comparing two XML files in a diff tool, format both with the same indentation first so the comparison lines up cleanly. The XML declaration and any comments survive both modes, so formatted output stays a complete, valid document. And because all parsing and serialising happens in your browser, you can tidy up XML that contains internal endpoints or credentials without any of it leaving your machine.
Frequently asked questions
Is my XML sent to a server?
What is the difference between Format and Minify?
Will formatting change the meaning of my XML?
What happens if my XML is malformed?
Does it keep comments and CDATA sections?
Related tools
YAML to JSON
Convert YAML into JSON.
JSON to YAML
Convert JSON into readable YAML.
Base64 Encoder & Decoder
Encode and decode Base64, with full UTF-8 support.
URL Encoder & Decoder
Encode and decode URL-safe text.
HTML Encoder & Decoder
Encode and decode HTML entities.
JWT Decoder
Decode and inspect JSON Web Token headers and payloads.