XML Formatter
Paste XML below to validate it and see a cleanly indented version as you type.
Validation and formatting run entirely in your browser — nothing is uploaded.
How it works
- Paste or type your XML into the input box — the formatted result appears instantly below.
- Choose 2-space or 4-space indentation, or press Minify to collapse the document onto one line.
- Press Copy to put the formatted or minified XML on your clipboard.
Frequently asked questions
- How does this XML formatter validate my XML?
- It parses your input with the browser’s native DOMParser, the same strict XML engine browsers use for feeds and SVG. If the document is not well-formed — an unclosed tag, a stray ampersand, mismatched quotes — the parser’s own error message is shown, usually with the line and column where parsing failed.
- Is my XML uploaded to a server?
- No. Parsing, formatting, and minifying all happen locally in your browser tab, and the page makes no network requests with your data. That makes it safe to format configuration files, API responses, or exports that contain private information.
- Can I minify XML as well as pretty-print it?
- Yes. The Minify button strips indentation and the whitespace between tags, producing a compact single-line document that is useful for embedding XML in code or reducing payload size. Press Pretty print to switch back to the indented view at any time.
- Does the formatter preserve attributes, comments, and CDATA sections?
- Yes. Attributes, namespaces, comments, processing instructions, CDATA sections, and the XML declaration are all kept in the output. Only insignificant whitespace between elements is rewritten; text inside mixed-content elements is left inline so its meaning does not change.
- What is the difference between 2-space and 4-space indentation?
- It is purely visual. Two spaces keep deeply nested documents narrow, which suits SOAP envelopes, Maven POMs, and Android layouts; four spaces make each nesting level easier to scan in shallow documents. Pick whichever matches your team’s style guide — the XML itself is identical.
About this tool
This free XML formatter turns cramped or machine-generated XML into a readable, consistently indented document. Paste any well-formed XML — an API response, an RSS feed, a SOAP message, a configuration file — and the pretty-printed version appears live as you type. If the input is invalid, you get the parser’s exact error message instead of a silently broken result, which makes the tool double as a quick XML validator.
Everything runs client-side in your browser. The input is parsed with the native DOMParser, so validation follows the real XML specification rather than loose pattern matching: undeclared entities, mismatched tags, and illegal characters are all caught. A custom serializer then walks the parsed tree and rebuilds the document with your chosen indentation, preserving attributes, namespace prefixes, comments, processing instructions, CDATA sections, and the XML declaration. Because no data ever leaves the page, it is safe to use with documents that contain credentials or personal data.
Typical uses include debugging web service responses that arrive as a single unreadable line, cleaning up XML exported from spreadsheets or databases before committing it to version control, and inspecting sitemaps, RSS or Atom feeds, SVG files, and plist or manifest files. The Minify mode does the reverse job: it removes inter-tag whitespace to produce the smallest equivalent document, handy when embedding XML in a string literal or trimming request payloads.
A few practical tips: whitespace between elements is treated as formatting and normalized, but text inside elements that mix text and child tags is kept inline, so document-style content such as XHTML fragments stays intact. If you see an error about an entity, remember that XML only defines five built-in entities — others must be declared or written numerically. Use Copy to grab the result once the output looks right.