XML Formatter & Beautifier Online
Beautify messy XML with clean indentation, check that it is well-formed, or minify it into one line.
XML Input
Formatted XML
What Is an XML Formatter?
An XML formatter (or XML beautifier) adds line breaks and indentation to XML so every element sits on its own line under its parent. This makes long, one-line XML from APIs, feeds and config files easy to read and debug. The formatter also checks that the XML is well-formed.
How to Format XML
- Paste your XML, click Upload, or drop a .xml file on the box.
- Choose 2 spaces, 4 spaces or Tab.
- Click Format XML, or Minify to put it on one line.
- Click Copy or Download to save the result.
Features
- Checks that the XML is well-formed and shows an error if not.
- Keeps attributes, comments, CDATA and the XML declaration.
- Colored result with line numbers.
- Minify option to remove all extra spaces.
- Runs in your browser. Your XML is never uploaded.
Example
<order id="7"><customer>Emily Clark</customer><items><item sku="A1">Notebook</item><item sku="B2"/></items></order>
<order id="7">
<customer>Emily Clark</customer>
<items>
<item sku="A1">Notebook</item>
<item sku="B2"/>
</items>
</order>What Makes XML Well-Formed?
If the formatter shows an error, check these rules:
- One root element must wrap everything, like
<order>…</order>. - Every tag must be closed:
<item>…</item>or self-closing<item/>. - Tags must be nested correctly:
<b><i>…</i></b>, not<b><i>…</b></i>. - Names are case-sensitive:
<Item>cannot be closed with</item>. - Attribute values need quotes:
id="7", notid=7. - Special characters must be escaped: write
&for & and<for < in text, or wrap the text in<![CDATA[ … ]]>.
Where You See XML Today
XML is still everywhere: RSS feeds, sitemaps, SOAP APIs, Office files (.docx and .xlsx are zipped XML), Android layouts, Maven pom.xml files and many bank and government data exchanges. If you need the data in a web app, convert it with XML to JSON, or go the other way with JSON to XML. Not sure which format to use? Read JSON vs XML.
Frequently Asked Questions
What does an XML formatter do?
It adds line breaks and indentation to XML so the structure is easy to read. It can also minify XML into one line.
Will it check if my XML is valid?
Yes. If the XML is not well-formed, for example a tag is not closed, the tool shows an error instead of a result.
Are comments and CDATA kept?
Yes. Comments, CDATA sections, attributes and the XML declaration are all kept.
Is my XML uploaded?
No. Formatting runs in your browser. Your XML stays on your device.