Tools
Guides

XML Formatter & Minifier

Format

Beautify or compress XML with fast-xml-parser. Normalises indentation, attributes and self-closing tags. Pure XML processing — no format conversion.

100% client-side No backend

Remote URLs are not fetched; paste your JSON directly.

Input
Output
Paste XML on the left, then choose Format or Minify.
On this page

What is an XML formatter?#

An XML formatter reflows a document that has lost its structure — a SOAP response dumped onto one line, an RSS feed pulled through a proxy that collapsed the whitespace, or a config file edited in a text box that did not preserve indentation — and re-indents it so the element hierarchy is visible. The reverse, minifying, strips every byte of inter-tag whitespace so the document is as small as possible for transport.

What makes XML round-tripping harder than it looks is that a naive find-and-replace on < and > destroys information. The order of elements, the <?xml?> declaration, comments, processing instructions like <?xml-stylesheet?>, attribute order, and the difference between <a></a> and <a/> all carry meaning. This page uses fast-xml-parser in preserve-order mode, which parses the document into an ordered tree and rebuilds it faithfully — so formatting is a normalised view of your document, not a re-sorted one. That is also why this tool is distinct from the JSON/XML converter: it does pure XML-to-XML round-tripping, never changing the data format.

How to use it#

  1. Paste your XML into the Input pane on the left. The placeholder shows a minimal <?xml?> document if you need a starting point, or click Sample.
  2. Pick a Mode button on the toolbar:
    • Format — parse, then rebuild with indentation and line breaks. Empty elements collapse to self-closing form (<a></a> becomes <a/>), attributes are preserved, comments and the declaration survive.
    • Minify — parse, then rebuild as a single compact line with no inter-tag whitespace and no trailing newline.
  3. In Format mode, choose an Indent: 2, 4, or tab.
  4. Read the result in the Output pane. The header shows the output size in characters; use Copy to take it. Clear resets both panes.

If your input is not well-formed — an unclosed tag, a stray & that should be &amp; — the status bar reports the error with a best-effort row and column, so you can find the problem instead of staring at a blank output.

Key features#

  • Faithful round trip. preserve-order parsing keeps document order, the <?xml?> declaration, comments and processing instructions through the format/minify cycle.
  • Both modes share one parser. Format and minify parse identically; they only differ in how the builder emits text. So if minify succeeds, format will too, and vice versa.
  • Self-closing normalisation. Empty elements like <a></a> collapse to <a/>, which is the canonical compact form and makes whitespace differences obvious when diffing.
  • Values stay strings. The parser is configured with parseTagValue: false, so a text node of true stays the string "true" and 007 stays "007". No silent type coercion that would surprise you on the way back.
  • Handles large inputs off the main thread. Documents larger than 1 MB are routed through a Web Worker, so the page stays responsive while parsing. Smaller inputs run inline.
  • Strictly client-side. The parser is bundled into the page; your XML never leaves the browser.

Worked example#

A small configuration document crammed onto two lines:

Input:

<?xml version="1.0"?><config><server host="example.com" port="443"/><feature name="cache"/><feature name="logs"></feature></config>

Click Format with 2 spaces:

<?xml version="1.0"?>
<config>
  <server host="example.com" port="443"/>
  <feature name="cache"/>
  <feature name="logs"/>
</config>

Two things stand out. The <?xml version="1.0"?> declaration survived the round trip at the top of the document. And both <feature name="logs"></feature> and the already-self-closing <feature name="cache"/> now appear as <feature name="logs"/> — empty elements were normalised to self-closing form, so the two features with the same shape actually look the same. Click Minify on the original input and you get the transport form:

<?xml version="1.0"?><config><server host="example.com" port="443"/><feature name="cache"/><feature name="logs"/></config>

Every byte of decorative whitespace is gone, but the attribute order on <server> is untouched and the declaration is still there.

FAQ#

What is the difference between this tool and the JSON/XML converter?#

This tool is XML in, XML out — it beautifies or minifies an XML document and hands you back XML. The JSON/XML converter on this site translates between the two formats, turning XML into a JSON object tree or vice versa. Use this page when you want the same format, just shaped better; use the converter when you actually want to change formats.

Does formatting preserve my comments?#

Yes. Comments are captured into the ordered tree during parsing and re-emitted by the builder, so <!-- note --> survives both Format and Minify. The processing instruction <?xml-stylesheet?> is preserved too.

Why is the error location sometimes approximate?#

The underlying parser does not expose character positions for every failure mode, so for some errors this page can only report a best-effort row and column parsed out of the parser’s message. For a missing close tag the location is usually precise; for more exotic parse failures it may default to row 1. The error message itself is always shown in full, which is typically enough to find the offender.

Can it handle very large XML files?#

Yes, up to your browser’s memory limit. Inputs above 1 MB are parsed inside a Web Worker so the UI does not freeze. For documents in the hundreds of megabytes, expect parsing to take noticeable time and memory — this is a browser tool, not a streaming server.