What this does
Two buttons over a pair of boxes. Beautify puts each element on its own line and indents it by nesting depth, at 2 spaces, 4 spaces or a tab. Minify squeezes the whitespace between tags out again so the document is a single line. The page beautifies the sample on load and re-runs whenever you change the indent, so the right-hand box always reflects the current setting. It is a small tokenizer running in your browser rather than a service, which is why a SOAP payload with real customer data is safe to paste.
How do I pretty-print XML?
- Paste the document into the left box.
- Pick an indent width.
- Click Beautify, then Copy.
<root><item id="1">A</item></root>
<root>
<item id="1">A</item>
</root>
Note the element with nothing but text inside it: <item>,
its content and its closing tag stay together on one line rather than being
split across three, which keeps leaf-heavy documents readable. Already-indented
input is re-indented from scratch, so a file where the spacing has gone ragged
comes out uniform.
Does it keep comments, CDATA and the XML declaration?
Yes. <!-- … --> comments, <![CDATA[ … ]]>
sections, the <?xml version="1.0"?> declaration, processing
instructions and a <!DOCTYPE> are each treated as a single
standalone token: their contents are never reindented or reflowed, and they are
placed on their own line at the current depth. Attributes stay on the element's
opening tag exactly as written — no reordering, no requoting, no line-wrapping
of a tag with many attributes. Self-closing tags like
<img src="x"/> keep their form.
Does this validate my XML?
No. It is a formatter, not a parser, and it will happily indent a document
whose tags do not match. Depth is tracked by counting opening and closing tags,
so an unclosed element makes everything after it drift one level to the right
and a stray closing tag pulls it back — that skew is often the quickest way to
spot the problem, but you get no error message. One tokenizer limitation worth
knowing: a tag ends at the first >, so an attribute value that
contains a literal > rather than > will be
split in the wrong place.
Will minifying change my content?
Minify removes whitespace that sits between a > and the next
<, and nothing else, so text inside an element is untouched —
<b>keep me</b> survives intact. The caveat is mixed
content: a deliberate space between two adjacent inline elements, as in
<b>a</b> <i>b</i>, is whitespace between
tags and does get removed. Beautify has the same blind spot from the other
direction — it trims text nodes and drops whitespace-only ones, so
xml:space="preserve" is not honoured. For element-only documents,
where XML is used purely as a data format, minifying a beautified document
gives you back exactly what you started with.
What kinds of XML is this useful for?
Reading a one-line SOAP or REST response out of a log, tidying a
pom.xml or an Android layout, inspecting an RSS or Atom feed, and
unpacking the hand-written SVG that a design tool exported without line breaks.
For SVG specifically, the SVG optimizer goes
further and strips metadata and redundant precision as well. If the payload you
are looking at is really JSON or YAML, use
the JSON formatter or the
JSON/YAML/TOML converter instead.