Nimble Toolbox

Format and minify XML

Paste your markup or drop an XML file, and it reformats as you type. Switching between format and minify re-applies straight away, and the document never leaves this tab.

How to use it#

  1. Paste your XML into the box, or drop a file on it, such as an .xml file, an SVG, a sitemap, an RSS feed, or a plist.
  2. Choose format to indent it, or minify to strip it back to one line.
  3. Pick 2 or 4 spaces of indentation when formatting.
  4. Copy the result, or download it. A dropped file keeps its own extension, with .formatted or .min added to the name.

Indenting rewrites the document#

Adding line breaks and spaces between elements adds characters to the document. For most XML that is harmless, because a parser reading a purchase order does not care whether the elements sit on one line or forty. It stops being harmless the moment whitespace carries meaning.

That happens in mixed content, where text and elements are siblings. In a paragraph like Hello <b>world</b>, again, the space before the bold element is part of the sentence, and pushing each child onto its own line would silently insert two more. Any element holding both text and child elements is written out on a single line here for that reason, exactly as it arrived.

The same caution applies to anything marked xml:space="preserve", and to content you are about to hash or sign. A digital signature covers the bytes, so reformatting a signed document invalidates it. Format a copy when the original has to stay verifiable.

What "not well-formed" means, and how to fix it#

XML has none of the forgiveness a browser extends to HTML. Every element that opens has to close, tags are case sensitive so <Title> does not close <title>, attribute values need quotes, and the whole document needs exactly one root element. Break any of those and a parser refuses the file outright rather than guessing.

A stray ampersand is the one that catches most people. A bare & starts an entity reference, so a URL with a query string in it, or a company name like Marks & Spencer, breaks the document unless the ampersand is written as &amp;. The less-than sign has the same problem, because it starts a tag.

As an XML validator, the page checks well-formedness, not a schema. The error line under the box comes from the browser parser itself and usually names the line and column where it gave up. That position is where the problem became undeniable rather than where it started, so an unclosed tag is typically reported at the point something else tried to close.

Minify for the wire, format for a person#

XML is verbose by design, and the indentation that makes it readable can be a fifth of the file. Stripping it out before a payload goes over a network is worth doing when the volume is high, which is why SOAP envelopes and RSS feeds usually arrive as one enormous line.

That is also why so much XML is unreadable when you meet it. Minified output is written for a parser, and a parser has no opinion about line length. Formatting is how you get a look at what a service actually sent you before you go looking for the field that is missing.

What survives a round trip#

Comments, CDATA blocks, processing instructions, the XML declaration at the top, and namespace declarations on any element are all carried through both directions. So are characters written as entities: an &amp; in the source comes back as an &amp;, not a bare ampersand that would break the document the next time it was parsed.

Formatting output that is already formatted produces exactly the same text, which means you can reformat a document repeatedly without it drifting. What is not preserved is the original whitespace between elements, since replacing it is the entire job.

Frequently asked questions#

Is my XML uploaded anywhere?

#

No. The parsing and formatting happen in this tab using the XML parser already built into your browser. Nothing is sent to a server, so a configuration file or an API response with customer data in it stays on your device.

What happens to my line breaks and spacing?

#

Whitespace between elements is replaced by the indentation you pick, which is the point of formatting. Whitespace inside the text of an element is left alone. An element holding only text keeps it exactly as written, spaces and line breaks included, and one holding both text and child elements is written on one line so the spacing around its words survives. Minify removes the indentation entirely.

Why does it say my XML is not well-formed?

#

Something in the document breaks a rule the parser cannot work around: an unclosed or mismatched tag, an unquoted attribute value, more than one root element, or a bare & or < inside text. The message names the line and column where the parser stopped, which is usually just after the real mistake.

Does it validate against a schema or a DTD?

#

No. It checks that the document is well-formed, meaning the syntax holds together. Validating that the elements are the ones an XSD or DTD expects, in the order it expects them, is a separate job and needs the schema itself.

Are comments and CDATA kept?

#

Yes. Comments, CDATA sections, processing instructions, and the XML declaration all come through both formatting and minifying. CDATA content is copied exactly, so the markup you deliberately hid inside it stays hidden.

Can I use it on HTML?

#

Only if the HTML happens to be well-formed XML, which most is not. Unclosed <br> and <img> tags, unquoted attributes, and bare ampersands are all legal HTML and all rejected here. For a web page, use the HTML formatter, which reads HTML by its own rules. An SVG file, on the other hand, is XML and formats fine here.