Skip to main content
ToolsHub

XML Formatter

Paste raw or minified XML and get clean, indented output that is easy to read and diff. Switch to minify mode to strip whitespace for production — all client-side.

Updated

Files never leave your browser

No output yet

Paste XML on the left to see the beautified or minified result here.

How to use XML Formatter

The XML Formatter beautifies raw or minified XML with proper indentation and line breaks, and can also minify formatted XML back to a compact single-line form for production use. Well-formatted XML is essential for readability when working with SOAP APIs, RSS/Atom feeds, SVG files, Android manifests, Maven POM files, and configuration formats like Spring XML. Validation catches malformed markup before it causes parser errors. All processing is client-side.

  1. Paste your raw, minified, or malformed XML into the input area, or upload an .xml file.
  2. Click Format to apply indentation (default: 2 spaces) and line breaks — the output is a human-readable version of the input.
  3. Alternatively, click Minify to strip all insignificant whitespace for a compact production payload.
  4. If the XML is not well-formed, the tool highlights the first error with a line number and description.
  5. Use the indent size selector to switch between 2-space, 4-space, or tab indentation.
  6. Copy the formatted output or download it as an .xml file.

Your data never leaves your device — 100% private processing.

XML structure rules and well-formedness

XML has strict well-formedness requirements defined by the W3C XML 1.0 specification. Every document must have exactly one root element. All elements must be properly nested — overlapping tags like <a><b></a></b> are illegal. Attribute values must be quoted (single or double). The characters <, >, and & must be escaped as &lt;, &gt;, and &amp; in text content; single and double quotes inside attribute values must be escaped as &apos; and &quot; respectively. Element and attribute names are case-sensitive and must start with a letter or underscore. XML is distinct from HTML in that it has no predefined tags and is used as a generic data serialisation format.

XML vs JSON comparison
FeatureXMLJSON
Human readabilityModerate (verbose)High (compact)
Data typesStrings only (schema adds types)Native number, boolean, null
AttributesYes (key="value" on elements)No — all data in values
CommentsYes (<!-- ... -->)No
NamespacesYes (xmlns:prefix="uri")No
Schema standardXSD, DTD, RELAX NGJSON Schema
Common useSOAP, RSS, SVG, config filesREST APIs, config, data exchange

XML namespaces and CDATA sections

XML namespaces (xmlns) prevent element name collisions when combining vocabularies from different specifications in a single document — for example, combining XHTML and MathML. A namespace is declared as xmlns:prefix="http://uri" and then applied by prefixing element names: <math:math>. The default namespace (xmlns="...") applies to all unprefixed elements within its scope. CDATA sections (<![CDATA[ ... ]]>) let you embed text containing < and & without escaping, which is useful for embedding HTML or JavaScript inside XML without a cascade of entity references. CDATA is a text node and carries no structural meaning — parsers strip the delimiters and return the raw text.

Worked examples

Pretty-print minified XML

Inputs: <a><b>1</b></a>

Result: indented, each element on its own line

Minify XML

Inputs: formatted multi-line XML

Result: single line, insignificant whitespace removed

Not well-formed

Inputs: <a><b></a></b>

Result: error: improperly nested tags (line 1)

Glossary

Well-formed XML
XML that satisfies all syntactic rules: single root, properly nested tags, quoted attributes, and escaped special characters.
XML namespace
A URI-identified scope declared with xmlns that qualifies element and attribute names to prevent collisions.
CDATA section
An XML construct (<![CDATA[ ... ]]>) that wraps text containing characters that would otherwise need escaping.
XSD
XML Schema Definition — a W3C standard for defining the structure and data types of XML documents.
XPath
A query language for selecting nodes from an XML document tree, used in XSLT transforms and XML validators.

Related reading

Free · No spam

Get weekly tool tips & updates

New tools, power-user tips, and productivity hacks — delivered free every Friday.

No spam, ever. Unsubscribe with one click.

Related Developer Tools

Explore all Developer Tools.