XML Formatter, Validator & Minifier

Paste messy or single-line XML to get it neatly formatted with 2 or 4-space or tab indentation, or minify it to the smallest size. Every input is validated as well-formed XML, with the line and column of any error. Comments, CDATA sections, namespaces, processing instructions and the XML declaration are all preserved. Open a file or paste text, then copy or download the result.

  • 100% free
  • No sign-up
  • Private & local
  • Works on mobile

Or drop an XML fileor browse files · XML, SVG, RSS, XSD, KML, GPX, .config

Private by design: every calculation runs locally in your browser. Nothing you type is sent to a server or stored by us.

What Is an XML Formatter?

XML (eXtensible Markup Language) is a text format for structured data, built from nested elements like <book><title>…</title></book>. It powers RSS and Atom feeds, sitemaps, SOAP web services, Microsoft Office files (DOCX and XLSX are zipped XML), SVG graphics, Android layouts, Maven and .NET project files, configuration files, KML and GPX maps, and countless enterprise data exchanges. XML generated by software is often written on a single line with no indentation, which is almost impossible for people to read.

This XML formatter (or XML beautifier) re-indents the document so its structure is clear, and the XML minifier does the opposite, stripping unnecessary whitespace to make files smaller for transmission and storage. Both first check that the XML is well-formed.

How to Format or Minify XML

  1. Paste your XML or drop a file (.xml, .svg, .rss, .xsd, .kml, .gpx, .config and more).
  2. Choose Format or Minify, and the indentation style.
  3. Optional: remove comments, or put each attribute on its own line for elements with many attributes.
  4. Fix any errors: if the XML isn't well-formed, you'll see the error message with its line and column.
  5. Copy or download the result.

Well-Formed XML Rules

An XML document is well-formed when it follows XML's syntax rules. Every parser rejects documents that break them:

  • There must be exactly one root element containing everything else.
  • Every start tag needs a matching end tag (<a></a>), or must be self-closing (<a/>).
  • Elements must be properly nested: <b><i></i></b>, never <b><i></b></i>.
  • Tag names are case-sensitive: <Item> and <item> are different.
  • Attribute values must be quoted, and each attribute can appear only once per element.
  • Special characters must be escaped: &amp; &lt; &gt; &quot; &apos;. Or wrap raw text in <![CDATA[…]]>.

Being well-formed is different from being valid, which means matching a schema (XSD or DTD) that defines which elements are allowed. This tool checks well-formedness, the most common source of errors.

Common XML Errors and Fixes

ErrorTypical causeFix
Opening and ending tag mismatchA missing or misspelled closing tagCheck nesting near the reported line
EntityRef: expecting ';'A bare & in text or a URLWrite &amp;, or use CDATA
Extra content at the end of the documentMore than one root elementWrap everything in one root
Attribute without value / not quotedHTML-style attributesUse name="value"
XML declaration allowed only at the startWhitespace or a BOM before <?xmlRemove anything before the declaration

XML Formatting in Other Tools

Many code editors can format XML too. VS Code does it with the XML extension, and IntelliJ-based IDEs have built-in formatting. On the command line, xmllint --format file.xml pretty-prints and validates XML on Linux and macOS. This online formatter is handy when you're away from your usual tools, need a quick check of an API response or SOAP message, or want to tidy an SVG before editing it.

XML vs JSON

JSON has replaced XML for most new web APIs because it's shorter and maps directly to JavaScript objects. XML remains essential where documents need attributes, mixed content, namespaces, schemas, comments or digital signatures, as in Office files, SVG, RSS, SOAP, SAML, sitemaps and many banking and government data standards. When you need to move data between the two, use the XML to JSON and JSON to XML converters.

Formatting Large Files

Very large XML files, such as database exports or multi-megabyte sitemaps, are processed entirely in your browser, so speed depends on your device. If a huge file is slow, format a representative section first to inspect its structure.

Frequently Asked Questions

Can I validate XML against an XSD schema here?

This tool checks well-formedness. Schema validation needs the XSD file and a validating parser, such as xmllint --schema.

Why does my formatted XML look different from the original?

Only whitespace between tags changes. Character entities may be written in a normalised form, but the data itself is identical.

Is my XML uploaded?

No. Parsing and formatting use your browser's built-in XML parser, locally.

Does formatting change my data?

Only whitespace between elements changes. Text content, attributes, CDATA and comments are preserved.

Can I format SVG files?

Yes. SVG is XML, so drop the file in to format or minify it.

How do I convert XML to JSON?

Use the XML to JSON converter, which handles attributes and repeated elements.

What's the difference between well-formed and valid XML?

Well-formed means correct syntax. Valid means it also follows a schema (XSD or DTD).