Skip to content
T
Tools.Town
Free Online Tools for Everyone
<root>\n <a/>\n</root>

XML Formatter

100% Free

Pretty-print or minify XML — handles XML declarations, comments, CDATA, self-closing tags, and HTML void elements.

Real-time
Client-Side
Well-formed
Mode
Indent
Output
Paste XML above…

Embed This Tool

Easy to Embed

Add XML Formatter to your website or blog in seconds.

  • Responsive design
  • Lightweight & fast
  • No backend required
  • Always up-to-date
<iframe
  src="https://tools.town/embed/xml-formatter/"
  width="100%"
  height="600"
  style="border:none; border-radius:12px;"
  loading="lazy"
  title="XML Formatter">
</iframe>

Share This Tool

Share Instantly

Share XML Formatter with anyone — no login required.

  • Shareable link
  • No login required
  • Works on any device
  • No account needed

Share via

Advertisement

How to Use

  1. 1 Paste any XML into the input box (or click 'Load sample')
  2. 2 Pick mode — Pretty (indented) or Minify (single-line)
  3. 3 For Pretty mode, choose 2-space, 4-space, or tab indent
  4. 4 Output updates as you type — copy with one click

Features

  • Pretty-print and minify modes
  • Three indent options (2/4/tab)
  • Preserves XML declaration `<?xml ?>`, comments, CDATA blocks
  • Handles HTML void elements (br, img, hr) as self-closing
  • Counts opening tags for quick complexity check
  • 100% client-side

Why it Matters

XML from a SOAP response or RSS feed often arrives as a wall of text on a single line — almost unreadable in a terminal. A reliable formatter that preserves CDATA verbatim and doesn't choke on processing instructions is the fastest path to understanding what you're looking at.

★★★★★

Use Cases

SOAP Response Debug

Pretty-print a SOAP envelope to find the bad element

RSS / Sitemap Cleanup

Format RSS/sitemap XML for human review before publishing

Bundle Minification

Strip whitespace from XML before embedding in code

Frequently Asked Questions

Can it validate XML against a schema (XSD)?
No — it's a syntactic formatter, not a validator. For XSD validation use libxmljs (Node), xmllint (CLI), or an XML editor like VS Code's XML extension.
Why does it preserve CDATA exactly?
CDATA blocks are meant to contain raw text (often code or markup) that mustn't be parsed. Reformatting their contents would break the intent — so we treat them as opaque tokens.
Will it handle malformed XML?
Best-effort. The tokenizer surfaces unclosed comments / CDATA / tags as errors. For more aggressive recovery use a real XML parser (libxml2 etc.).
Does it support XML namespaces?
Yes — namespace prefixes (e.g. `<svg:rect>`) are preserved as-is. The formatter doesn't validate namespace declarations though.

Related Tools You Might Like

Browse more free tools