Developer Tools

XML Formatter

Inspect an XML payload before you edit or share it. This formatter reports malformed markup, counts elements and attributes, and adds indentation to compact element-only sections without stripping existing text.

Free online tool

Loading tool…

182 / 500,000 characters. Processing stays in this browser.

Validate and format XML

Text, mixed content, existing whitespace, CDATA, comments, and xml:space="preserve" stay intact. Indenting compact element-only content adds whitespace text nodes; choose preserve mode if every character matters.

Supports XML 1.0, ASCII element/attribute names, and declared namespace prefixes. DTDs, custom entities, external references, XML 1.1, and non-UTF-8 declarations are rejected. Limits: 64 levels, 50,000 nodes, 1,000 attributes per element.

All parsing and exports run locally in your browser. Example records are original fictional data, not an external dataset.

GET STARTED

How to use the XML Formatter

  1. 01

    Paste XML or open a UTF-8 text file.

  2. 02

    Choose two-space, four-space, or preserve-spacing mode, then validate.

  3. 03

    Review the structure counts and copy or download the normalized XML.

Examples

Compact catalog

<catalog><item id="a1"><name>Pen</name></item></catalog> gains readable line breaks in indentation mode.

Mixed content

<p>Hello <b>world</b>!</p> stays inline so the spaces around world keep their meaning.

Choose a whitespace policy deliberately

XML text can be meaningful even when it looks like layout spacing. The formatter preserves existing text nodes, including whitespace-only nodes. It inserts indentation only where every direct child is an element, comment, or processing instruction. An inherited xml:space="preserve" prevents insertion. Preserve-spacing mode is best for documents whose text nodes are compared exactly.

Normalization you can expect

Attributes use double quotes, empty elements use self-closing tags, and parsed character references are escaped as needed. XML line endings are normalized. Formatting is not canonical XML and must not be used to prepare a digital signature.

Conservative validation scope

One root element is required. ASCII names, quoted attributes, namespaces, comments, CDATA, and processing instructions are supported. DTDs and custom entities are refused during tokenization. No referenced resource is fetched. Unicode element names and non-UTF-8 encoding declarations fall outside this tool’s supported subset.

What to know

  • Input is limited to 500,000 characters. Review the supported syntax and export policy described above.

Common questions

Why did an already spaced document barely change?

Existing whitespace is retained intentionally. Replacing it could change document text. The indentation option primarily expands compact element-only markup.

Does formatting validate an XSD or DTD?

No. It checks supported XML syntax and namespace declarations, not a business schema. DTD declarations are rejected.

Can I use ampersands in text?

Escape literal ampersands as &amp;. The five predefined entities and valid decimal or hexadecimal character references are supported.

Sources & references