Text

XML Formatter

Format, validate, or minify XML and locate syntax errors without uploading your data.

Quick guide

How to use the XML Formatter

  1. Enter or choose xml, action, indentation.
  2. Select Process XML.
  3. Review the main result, supporting breakdown, and step-by-step calculation notes.
  4. Copy the output or download the generated file when available.

What this tool does

Validate, pretty-print, or minify XML documents directly in your browser using native XML parsing and serialization. Unlike naive regex formatters that corrupt entities or break mixed-content whitespace, this engine preserves XML declarations, comments, entity escapes (&, <), xml:space="preserve" blocks, and stops cleanly on the first syntax error.

Calculation method

  1. Parse the input strictly with DOMParser("application/xml") and halt immediately with the parser’s error description if the XML is not well-formed.
  2. Preserve XML declarations, processing instructions, comments, attribute escaping, CDATA sections, and mixed-content text nodes.
  3. Apply 2-space, 4-space, or tab indentation in Format mode—or strip only insignificant element-only indentation in Minify mode—and prepare a UTF-8 XML download.

Good to know: XML is parsed and transformed only in this browser tab.

Example: formatting XML while preserving escaped entities

Input: <catalog><item id="1"><title>Tom &amp; Jerry &lt;3</title></item></catalog>

Result: Indented multi-line XML retaining &amp; and &lt; intact, plus local formatted.xml download

Proper XML serialization keeps special characters escaped so the formatted output stays 100% valid XML when re-parsed by downstream tools.

The 5 predefined XML character entities

CharacterRequired XML EntityWhere Needed
&&amp;Always in text and attribute values
<&lt;Always in text and attribute values
>&gt;Recommended in text (required in ]]> )
"&quot;Inside double-quoted attribute values
'&apos;Inside single-quoted attribute values

Practical uses

  • Formatting unreadable minified SOAP or REST XML payloads
  • Validating RSS feeds, sitemaps, and SVG markup
  • Minifying Android/Maven/config XML without breaking text nodes
  • Inspecting private XML configs locally without cloud uploads

Accuracy tips and common mistakes

  • Unescaped ampersands (such as “A & B” instead of “A &amp; B”) are the #1 cause of XML syntax errors.
  • Add xml:space="preserve" on elements whose leading/trailing spaces are semantically significant—both Format and Minify modes respect it.
  • Downloads are normalized to UTF-8 encoding so modern editors open them consistently.
Frequently Asked

XML Formatter – Frequently Asked Questions

Common questions, edge-cases, and mathematical explanations.

Why does the validator reject an ampersand like “R&D” in XML?

In XML syntax, & always starts an entity reference. A literal ampersand must be written as &amp; (so “R&amp;D”) to be well-formed XML.

Does Minify mode strip spaces inside mixed text elements like <p>Hello <b>world</b></p>?

No. It only strips whitespace-only formatting nodes between element children, preserving significant spaces inside text and mixed content.

Does XML Formatter validate against an XSD or DTD schema?

It checks strict XML well-formedness (matching tags, valid attributes, proper escaping, single root element). External XSD/DTD schema validation is outside browser-local parsing.

Analytics preferences

Optional Google Analytics cookies help us understand visits and improve our tools. Analytics is off until you allow it. Your tool inputs and files are never included in our analytics events. Read our privacy policy.

Analytics is off.