Format Code Now
/

XML Minifier

FV-11

Paste XML to remove the whitespace that sits between tags. Text content, CDATA sections and anything marked xml:space preserve are kept exactly.

Runs in your browser. Nothing is uploaded.

XML

Minified XML

How to use it

  1. Paste your XML into the input box, or open an .xml file (up to 5 MB).
  2. Leave Remove comments ticked, or untick it to keep them.
  3. Choose Minify and copy or download the result.
  4. Choose Size saved to see the byte count before and after.

What counts as removable whitespace

Only whitespace-only text between tags is removed, such as the line breaks and indentation between a parent element and its children, and only where no element around it holds text. Text that contains any visible character is never touched. Inside an element that has both text and child tags, such as a paragraph with bold words, all spaces are kept, including inside tags nested in it, because they can be part of the content. Spaces between attributes are reduced to one.

CDATA, xml:space and comments

CDATA sections are copied exactly and count as text. An element with xml:space="preserve" keeps all its whitespace, and so do its children, until a descendant sets xml:space="default". Comments are removed by default; untick the option to keep them. Processing instructions such as the XML declaration are always kept, and a DOCTYPE with an internal subset is copied as written.

What it checks

The tool follows the tag structure while it works, so it reports a closing tag that does not match, an unclosed element, an unclosed comment or CDATA section, and text outside the root element. It does not validate against a schema or DTD, check attribute rules or resolve entities. For a well-formedness and layout check with indentation, use the XML Formatter on this site.

Error messages and what to do

MessageWhat it meansFix
Closing tag </b> at line 5 does not match <a> opened at line 3.The closing tag is not the one for the element that is currently open.Fix the nesting or the tag name so each element closes in order.
<item> opened at line 8 is never closed.An element has no closing tag before the document ends.Add the closing tag, or make the element self-closing with />.
Text outside the root element at line 1.Characters other than whitespace appear before or after the root element.Remove the stray text, or wrap everything in one root element.

Questions people ask

How do I minify XML?

Paste the XML, choose Minify and copy the output. Indentation and line breaks between tags are removed. Text values, CDATA and preserved elements stay as they were.

Does removing whitespace change my data?

Whitespace-only text between elements is usually just formatting, but an application can treat it as data. That is why mixed-content elements and xml:space="preserve" are left alone. If your consumer reads ignorable whitespace, compare the result before you rely on it.

Are XML comments removed?

Yes by default, and you can untick Remove comments to keep them. Processing instructions, including the XML declaration at the top of the file, are always kept as written, whichever way the option is set.

What happens to CDATA sections?

They are copied exactly, including any spaces and line breaks inside them. A CDATA section also counts as text, so the element that holds it keeps its whitespace-only text between children too, not just the CDATA itself.

Can it minify SOAP, RSS or SVG files?

Any well-formed XML works, which includes those formats. For SVG, note that whitespace inside text elements can matter, and those elements hold text, so their spaces are kept. Test the result in your target program.

Does it validate my XML?

Only for structure: matching tags, closed comments and CDATA, and no text outside the root element. It does not check a schema, a DTD, attribute rules or entity names.

About this tool

Removes whitespace-only text between tags, where it carries no data, and collapses spaces between attributes. Text that contains any non-space character is never changed, and neither are CDATA sections. Elements that mix text and child tags, such as <p>Mixed <b>a</b> <i>b</i></p>, keep their spaces, as do all elements nested inside them (whitespace-only text is removed only where no element around it holds text), and so does everything inside an element marked xml:space="preserve". Comments are removed unless you turn that off. The tool checks that tags open and close in the right order, but it does not validate against a schema or DTD and does not resolve entities. A DOCTYPE with an internal subset is copied as written.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.