XML Formatter

Paste or upload XML to instantly format, validate or minify it. Everything runs in your browser — your data never leaves your device.

Read the guide: How to format XML
3 of 3 free uses remaining today
3 formats remaining

Input

0 chars · 0 lines
Drop a .xml file to load itUp to 5.0 MB per file
Indentation:

Formatted XML

Formatting results will appear here.

Your XML is processed to provide formatting and validation. XML contents are not included in analytics.

How the XML Formatter works

  • Your XML is parsed using the browser's built-in DOMParser, which checks the document is well-formed.
  • For formatting, the parsed document is re-serialised with your chosen indentation (2 spaces, 4 spaces or tabs).
  • For minifying, it is re-serialised with no unnecessary whitespace while preserving text content, comments and CDATA.
  • If parsing fails, the error is shown with the line and column where the problem was found.

See also: JSON Validator, JSON Formatter and JSON Minifier.

Examples

Compact XML

<?xml version="1.0" encoding="UTF-8"?>
<catalog><book id="1"><title>Example</title><author>John</author></book></catalog>

Nested elements

<root>
  <items>
    <item id="a">Value</item>
  </items>
</root>

Useful tips

  • Use Validate first on broken XML to find the error before formatting.
  • Choose 2 spaces, 4 spaces or tabs for formatting — the data stays the same.
  • Upload a .xml file to format it instantly without pasting.
  • Minify XML to create compact output for production use.

Frequently asked questions

What is an XML Formatter?+

An XML Formatter takes XML text and adds consistent indentation and line breaks to make it easier to read. It parses the XML, checks it is well-formed, and re-serialises it with your chosen indentation (2 spaces, 4 spaces or tabs).

How do I format XML?+

Paste your XML into the editor or upload a .xml file, then click Format XML. The tool validates the XML first and, if well-formed, produces neatly indented output you can copy or download.

How do I beautify XML?+

Formatting and beautifying XML are the same thing. Click Format XML to add indentation and line breaks that make the structure easier to read. You can choose 2 spaces, 4 spaces or tabs for indentation.

Does formatting XML change the data?+

No. A proper formatter preserves the XML structure, attributes, namespaces, comments, CDATA blocks and text content. Only the presentation whitespace (indentation and line breaks between elements) is changed. Meaningful whitespace inside text nodes is preserved.

Can I format an XML file?+

Yes. Click Upload XML File and choose a .xml file. The file is loaded as text into the editor and you can format, validate or minify it instantly. The maximum file size is 5 MB.

What is XML pretty printing?+

XML pretty printing is another name for XML formatting. It adds whitespace and indentation to compact or unformatted XML so the nesting structure is visible and the document is easier to read and debug.

What is the difference between XML formatting and XML validation?+

Validation checks whether your XML is well-formed (correct syntax, matching tags, proper nesting). Formatting re-indents valid XML for readability. A formatter should validate first — if the XML is not well-formed, it cannot be formatted.

Can I minify XML?+

Yes. Click Minify XML to remove unnecessary formatting whitespace while preserving the XML content, comments, CDATA, attributes and namespaces. The result is compact XML that is still valid.

Does XML support comments?+

Yes. XML comments are written as <!-- comment text -->. The XML Formatter preserves comments in both formatted and minified output.

Can XML contain CDATA?+

Yes. CDATA sections (<![CDATA[ ... ]]>) allow you to include text that would otherwise need escaping, such as JavaScript or HTML. The XML Formatter preserves CDATA blocks without altering their content.

Is my XML stored when I use the formatter?+

No. Your XML is processed entirely in your browser and is never uploaded or stored. We do not include your XML content in analytics.

Related guides

What would you like to do next?