XML Formatter

Pretty-print or minify XML documents.

Open tool

Overview

The XML formatter pretty-prints or minifies an XML document. Pretty mode indents nested elements consistently, normalises attribute spacing, and places each element on its own line. Minify mode strips all optional whitespace for compact transmission.

It's a routine inspection tool when working with SOAP responses, RSS feeds, configuration files, or any XML payload that arrived as a single unreadable line. Backend developers and integration engineers use an xml beautifier to diff payloads, copy snippets into docs, or simply read what an upstream system sent.

How it works

The formatter parses the input as XML 1.0 using a tolerant front-end that accepts unbound prefixes and other minor sins (so a fragment without a root namespace declaration still formats). Elements, text nodes, processing instructions, CDATA sections, and comments are preserved exactly; only whitespace between elements is rearranged.

CDATA sections keep their contents byte-for-byte, including embedded whitespace. Mixed content (text and elements interleaved) is preserved without inserting indentation that would change semantics — XML treats inter-element whitespace as significant in mixed content, and the formatter respects that.

Examples

Input:
<order id="1"><item sku="abc">Widget</item><item sku="def">Gizmo</item></order>
Output:
<order id="1">
  <item sku="abc">Widget</item>
  <item sku="def">Gizmo</item>
</order>
Minify input:
<root>
  <a>1</a>
  <b>2</b>
</root>

Minify output:
<root><a>1</a><b>2</b></root>

FAQ

Does it preserve attribute order?

Yes. XML doesn't formally require attribute order to be preserved, but humans expect it for diff-friendly output, and the formatter keeps the source order. Sorting alphabetically is opt-in.

What about XML namespaces?

Namespace prefixes and declarations are preserved exactly. The formatter never rebinds prefixes or moves namespace declarations, so xmlns: attributes stay on the same element they were declared.

Can it validate the XML?

The formatter checks well-formedness (matching tags, no overlapping elements). For schema validation, use a tool that supports XSD or RELAX NG — well-formedness and schema validity are separate concerns.

Try XML Formatter

An unhandled error has occurred. Reload ×