Accueil XML Formatter

XML Formatter

Beautify, validate and format XML with adjustable indentation — 100% in your browser.

Input

Output

Original
Result
Type

What is XML formatting?

XML formatting (or beautification) is the process of re-indenting and re-structuring an XML document so that its element hierarchy is visually clear. A formatter adds consistent line breaks and indentation, removes unnecessary whitespace between elements, and ensures that the document is easy to read and edit by hand.

Machine-generated XML is often minified or has inconsistent indentation to save space. While efficient for transfer, this makes it hard to read and debug. An XML formatter (also called a pretty-printer) re-introduces proper indentation so you can see the structure at a glance.

Why format XML?

Formatting XML delivers several benefits. First, it makes the document human-readable, which is essential for debugging, code review, and manual editing. Second, it reveals structural errors that might be hidden in minified XML — mismatched tags, missing closing elements, and incorrect nesting become visible. Third, formatted XML is easier to diff in version control, as each element is on its own line.

This formatter also validates the XML: if the input is not well-formed (e.g., has mismatched tags or invalid characters), the parser reports an error immediately. This helps you catch problems before deploying or sharing the document.

When to use an XML formatter

An XML formatter is useful in many scenarios:

  • Reading API responses. Paste a SOAP or REST XML response to read its structure clearly.
  • Editing configuration files. Format XML configs (like Spring, Maven, or web.config) to make them easier to edit.
  • Debugging XML data. Spot structural errors, missing tags, or incorrect nesting in XML data.
  • Preparing SVG files. Format SVG graphics to inspect or modify their structure.
  • Version control. Format XML before committing so diffs are clean and meaningful.

How to format XML

Formatting XML with this tool takes a second and happens entirely in your browser. Follow these steps:

  1. Choose indentation. Select 2 spaces or 4 spaces from the indentation dropdown.
  2. Paste your XML. Enter the XML you want to format in the input box.
  3. Click "Convert" and copy. The formatted XML appears in the output box with proper indentation and an XML declaration.

If the XML is invalid, you'll see an error message describing the problem. Fix the XML and try again.

Common XML issues

The formatter parses the XML into a DOM tree using the browser's built-in DOMParser, then re-serialises it with consistent indentation. This means the output is semantically identical to the input — only the whitespace and formatting change. Attributes are preserved, empty elements are self-closed (<element/>), and text content is trimmed of extra whitespace.

Common XML errors include: mismatched tags (opening and closing tag names differ), unclosed elements (missing closing tag), unescaped special characters (& must be &amp; in text content), and invalid attribute values (must be quoted). The parser will report these errors with a description of the problem location.

Is this XML formatter free?

Yes, completely free with no sign-up, no limits beyond your device's memory, and no upload.

Does it validate XML?

Yes. The formatter parses the XML strictly and reports any well-formedness errors, such as mismatched tags or invalid characters.

Can I choose between 2 and 4 space indentation?

Yes. Use the indentation dropdown to select 2 spaces or 4 spaces. The default is 2 spaces.

Is my data uploaded?

No. All formatting is local. Your XML data never leaves your browser.