curly{bits}

curlybits / XML Formatter

XML Formatter & Validator

Paste XML to indent it neatly, or minify it to a single line. If it isn't well-formed, you'll see the exact line and column of the problem. Comments, CDATA, namespaces and the XML declaration are kept.

Input XML
Formatted XML

      

How to use the XML Formatter & Validator

  1. Paste your XML into the left box, or click Load sample.
  2. Choose an indent (2 spaces, 4 spaces or tab), or tick Minify instead to remove the whitespace between tags.
  3. Read the result on the right. If the XML is broken, the status bar shows the line and column, and the cursor jumps there.
  4. Click Copy to grab the result.

What the formatter keeps

The XML is parsed by your browser's own XML parser, so the result is exactly what other XML tools will read. Formatting only changes the whitespace between tags:

  • The <?xml version="1.0"?> declaration, <!DOCTYPE>, comments and processing instructions
  • <![CDATA[…]]> sections, unchanged
  • Namespaces and prefixes such as soap:Envelope and xmlns:xsi
  • Mixed content like <p>Hello <b>world</b></p> and anything marked xml:space="preserve", which are left as written so no spaces are added or lost

Common XML errors

  • Mismatched or unclosed tags: every <item> needs a matching </item>, or write it as <item/>.
  • A bare ampersand: write &amp; instead of & in text and attributes. The HTML escape tool can convert text for you.
  • Unquoted attributes: id=1 must be id="1".
  • More than one root element: an XML document must have exactly one top-level element.
  • Text before the declaration: <?xml …?> must be the very first thing in the file, with nothing before it.

Where you'll meet XML

SOAP APIs, RSS and Atom feeds, sitemaps, Android layouts, Maven pom.xml, .NET config files, SVG images, Office documents and many bank and government data exchanges all use XML. Need JSON instead? Most APIs offer both. For SVG files, the SVG optimizer also shrinks them.

Frequently asked questions

Is my XML uploaded anywhere?

No. Parsing and formatting happen in your browser. Your data never reaches a server, so it's safe for config files and API responses.

Does it validate against a schema (XSD or DTD)?

It checks that the XML is well-formed: tags match, attributes are quoted and there's a single root element. It doesn't check it against an XSD or DTD schema.

Will formatting change my data?

Only the whitespace between tags. Text, attributes, CDATA and comments stay the same, and elements with mixed text and tags are left exactly as written.

How do I minify XML?

Tick Minify instead. Whitespace between tags and comments are removed, and the status bar shows how much smaller the result is.

Add this XML formatter to your website

Free for blogs, schools and businesses. Copy the code below and paste it into your page's HTML. The tool works exactly like this one and runs in your visitors' browsers, so nothing is uploaded. Please keep the credit line so others can find it too.

Preview embed ↗