XML Formatter and Minifier

Paste XML to indent it for reading, minify it for transfer or check that it is well-formed, with the parser error shown in place of the output. It is free, instant and private, because it runs entirely in your browser.

XML Formatter and MinifierPrivate · runs on your device
Input
Words 0Characters 0Lines 0
Formatted XML

Example: <a><b>1</b><c/></a> → <a> <b>1</b> <c/> </a>

How to use the XML formatter

Paste a document and choose what you want back. The output updates as you type.

  1. Paste your XML into the Input box, or press Paste. Try it loads a short example.
  2. Set Mode to Beautify to put each element on its own line, or to Minify to remove the line breaks and indentation between elements.
  3. Choose the Indent: 2 spaces, 4 spaces or Tab. It only affects Beautify.
  4. Read the status line. For good input it reads "Well-formed XML" with the root element and the number of elements. For bad input it says "Not well-formed" and quotes the browser parser, usually with a line and column.
  5. Press Copy or Download .txt. Use as input moves the result back into the input box.

The document is parsed by the XML parser built into your browser and is never uploaded, so SOAP envelopes, exports and configuration files stay on your machine.

Well-formed is not the same as valid

A document is well-formed when it follows the syntax rules: one root element, every start tag closed by a matching end tag, correct nesting, quoted attribute values, no repeated attributes, and only the five predefined entities (&amp;, &lt;, &gt;, &quot; and &apos;) unless others are declared. It is valid when it also matches a schema, such as an XSD or DTD, that lists which elements and attributes are allowed.

This tool checks well-formedness only. The messages come from the browser, so wording varies, but these are the ones you will meet most:

  • <a>x & y</a> fails because a bare ampersand must be written as &amp;.
  • <a><b></a> fails with an opening and ending tag mismatch.
  • <a>&nbsp;</a> fails with "Entity nbsp not defined", because nbsp is an HTML entity, not an XML one.
  • <a/><b/> fails with extra content at the end, since there are two root elements.

What the formatter changes in your markup

The tool parses the document and writes it out again, so it is a rewrite, not a whitespace edit. In the example, <a><b>1</b><c/></a> becomes four lines, with b and c indented one level under a. Elements that contain only text stay on one line. These details are worth knowing before you save the result:

  • Spaces at the start and end of text are trimmed, and text that is only whitespace between elements is dropped.
  • In mixed content, such as <p>Hello <b>world</b> again</p>, Beautify puts the text and the child element on separate lines, and Minify joins them as Hello<b>world</b>again. The spaces are lost, so do not use the tool on text where those spaces matter.
  • Empty elements are always written as self-closing, so <empty></empty> becomes <empty/>.
  • Single-quoted attributes get double quotes, and attribute order is kept.
  • Comments, CDATA sections, processing instructions and the XML declaration are kept, and CDATA content is not touched.
  • A DOCTYPE line is not carried over to the output.
  • Quotation marks inside text are written as &quot;.

Where XML still turns up

XML is less fashionable than JSON, but a lot of everyday files are XML and arrive as one unreadable line. SOAP and older web service responses, RSS and Atom feeds, XML sitemaps, Maven pom.xml and .csproj files, Android layouts, SVG graphics and Office documents, which are zipped XML, all benefit from indentation before you read or review them.

Beautify before a code review or when hunting for one field in a response, and Minify before embedding a snippet in a string. If the markup is HTML rather than XML, the HTML formatter is more forgiving, because HTML allows unclosed tags that XML rejects. Use the diff checker to compare two formatted versions, and the JSON formatter if the same data is also offered as JSON. The URL encoder and decoder helps when an XML value has been percent-encoded.

Quick answers

Frequently asked questions

The questions people ask most, answered in plain words.

What does well-formed XML mean?

Well-formed XML follows the basic syntax rules: a single root element, matching start and end tags, correct nesting, quoted attribute values and properly escaped special characters such as ampersands and angle brackets. Every XML parser requires it. Validity against a schema is a separate, stricter check that this tool does not perform.

Does formatting change the meaning of my XML?

It can, in whitespace. Elements, attributes, text, comments and CDATA are kept, but leading and trailing spaces in text are trimmed, and Minify removes the spaces around child elements in mixed content. A DOCTYPE line is also dropped. Check the result if your document depends on exact spacing.

Why does the formatter say an entity is not defined?

XML predefines only five entities: amp, lt, gt, quot and apos. Names from HTML, such as nbsp or copy, are undefined unless a DTD declares them. Replace them with a numeric character reference or the real character. A bare ampersand in text or a URL gives a similar error and must be written as amp.

Can I format SVG, RSS feeds or sitemap files?

Yes. SVG, RSS, Atom, sitemaps, SOAP envelopes, Maven files and Android layouts are all XML, so they indent and minify the same way. Minifying an SVG only removes line breaks and indentation between tags. It does not simplify paths or strip editor metadata, so use an SVG optimiser for that.

Does it validate against an XSD or DTD?

No. It checks well-formedness with the parser built into your browser, which catches syntax errors such as unclosed tags and bad entities. Matching elements and attributes to a schema needs a validating parser with access to the XSD or DTD, which is better done in your editor or build tooling.