An XML formatter takes XML that is squashed onto one line, or indented unevenly by three different people, and prints it again with tidy nesting so a human can read it. It also tells you whether the XML is well-formed, which is the first thing that goes wrong when you edit a feed or config by hand. Our free XML Formatter does both in your browser, with a Beautify and a Minify mode, a choice of indent, and a few switches for comments, attributes and empty tags.
This guide is for developers, testers, people who maintain RSS feeds and sitemaps, and anyone who has received an .xml file from a bank, a government portal or an API and cannot tell where one record ends. It covers every control, what the tool leaves alone, and how to read each error message.
What XML Formatter does
It reads your XML, checks the syntax, and prints it again in the style you choose. The data stays the same; only the layout changes.
It can:
- Beautify XML, with 2 spaces, 4 spaces or tabs.
- Minify XML into one line.
- Keep or remove comments.
- Sort the attributes inside each tag from A to Z.
- Write
<a></a>as<a/>. - Show the number of elements, attributes and comments, the deepest level, and the size before and after.
It does not validate against a schema (DTD or XSD), it does not fix broken XML, and it does not convert to other formats. If a document is not well-formed you get an error with a line and column, not a guess.
How to use XML Formatter, step by step
- Open XML Formatter.
- Paste your XML into the box labelled "Paste XML or open an .xml file". You can also press Open file, or press Sample to see how the tool behaves.
- Under Options, choose Mode: Beautify or Minify. With Beautify, choose the Indent.
- Set Comments to Keep comments or Remove comments, and tick Sort attributes A–Z or Collapse empty elements if you want them.
- Read the result in the panel on the right, titled Formatted XML (or Minified XML). A green note confirms the XML is well-formed.
- Press Copy, or Download .xml to save the file.
The page formats as you type, after a short pause of about 0.3 seconds. If you open a file, the downloaded name follows it: feed.xml is saved as feed.xml, and a minified copy as feed.min.xml. With nothing opened, the names are formatted.xml and formatted.min.xml. Like every download on this site, the file name starts with "Tech Solution Point - ".
Every option explained
Mode: Beautify or Minify
Beautify puts each element on its own line and indents it by nesting level. Use it for reading, code review and finding the part of a document you care about.
Minify removes the layout between elements and joins everything, including the XML declaration, onto one line. Use it when you want the smallest file or need to paste XML into a one-line field. After a Minify run, the Size line under the panels shows how many bytes were saved.
Indent: 2 spaces, 4 spaces or Tabs
The Indent list appears only in Beautify mode, because a minified file has no indentation. Two spaces keeps deeply nested XML narrow, four spaces is easier to scan, and Tabs suits editors set to show tabs at your preferred width.
Comments: Keep comments or Remove comments
Keep comments writes every <!-- ... --> back where it was. Remove comments drops them, including comments that sit inside an element that also holds text, and a note under the panels tells you how many were removed, for example "1 comment removed." Use this before sending a file to someone outside your team.
Sort attributes A–Z
This puts the attributes inside each tag in alphabetical order, so <student id="S101" dept="science"> becomes <student dept="science" id="S101">. The order is by character code, so capital letters come before small ones. It is useful before comparing two files, because two tags with the same attributes in a different order then look identical. Element order is never changed.
Collapse empty elements
With this ticked, <hobby></hobby> is written as <hobby/>. Without it, the tool keeps each empty element the way you wrote it: a self-closing tag stays self-closing, and an open-and-close pair stays as a pair. Both forms mean the same thing in XML.
A worked example
Suppose a college system exports this on a single line:
<?xml version="1.0" encoding="UTF-8"?><students><!-- HSC 2026 batch --><student id="S101" dept="science"><name>Rahim Uddin</name><phone>01712345678</phone><gpa>4.83</gpa><remarks>Passed <b>with</b> distinction</remarks><hobby></hobby></student><student dept="arts" id="S102"><name>Nusrat Jahan</name><gpa>5.00</gpa><hobby/></student></students>
With Beautify and 2 spaces, the output is:
<?xml version="1.0" encoding="UTF-8"?>
<students>
<!-- HSC 2026 batch -->
<student id="S101" dept="science">
<name>Rahim Uddin</name>
<phone>01712345678</phone>
<gpa>4.83</gpa>
<remarks>Passed <b>with</b> distinction</remarks>
<hobby></hobby>
</student>
<student dept="arts" id="S102">
<name>Nusrat Jahan</name>
<gpa>5.00</gpa>
<hobby/>
</student>
</students>
The stats read 12 elements, 4 attributes, a depth of 4 and 1 comment. Notice three things. The <remarks> line stays as one line, because it holds text and a child element, so its spaces are content. The 5.00 is not turned into 5, because XML has no numbers, only text. And the two hobby tags keep their different forms.
Now choose Remove comments, tick Sort attributes A–Z and Collapse empty elements. The comment disappears, dept moves before id in the first student, and the first hobby becomes <hobby/>.
What it accepts and its limits
- Input: any well-formed XML text, with or without an XML declaration. A byte-order mark at the very start is ignored.
- Files: Open file accepts
.xml,.svg,.rss,.atom,.xhtml,.xsd,.xsl,.xsltand.txt. - Size: input over 10 MB is rejected, and so is XML nested more than 512 levels. Above 1 MB the page does not format while you type; a Format button appears and you press it when ready.
- DOCTYPE: accepted and written back as it was. If it declares entities, a note says they are kept as written and never expanded.
- Entities: only the five built-in ones (
<,>,&,",') and numeric references such asকare understood.
Privacy
The XML Formatter runs in your browser. Your text is not sent to our server, so private feeds, configuration files and API payloads are safe to paste. It also never loads external files or expands custom entities, so an untrusted document cannot make it fetch anything or blow up in size.
Common problems and how to fix them
When the XML is not well-formed, the output panel is replaced by a red box headed "Not well-formed: line 3, column 9", with the reason, the offending line and a caret under the spot. Press Go to error and the input box selects that character. These are the messages you will meet most.
Closing tag does not match the open tag
The full message is: Closing tag </a> does not match the open tag <c> (opened at line 1, column 12). A tag was left open or closed in the wrong order. The message tells you where the open tag started, so look there first.
Unescaped "&"
Write & for a literal ampersand. This is the classic problem with web addresses: ?page=1&sort=asc inside an element must be ?page=1&sort=asc. A bare < in text, such as 5 < 6, needs < in the same way.
Unknown entity
XML knows only five named entities. HTML ones such as and © are errors. Use the character itself (it is fine in UTF-8) or a numeric reference such as  .
The value of attribute must be in quotes
<a id=5> is valid HTML but not XML. Write <a id="5">.
The XML declaration must be the very first thing
If <?xml ...?> has a space or blank line before it, the parser refuses. Delete whatever comes before it.
Only one root element is allowed
An XML file has exactly one top-level element. Two siblings at the top, such as <a/><b/>, need a wrapper element around them.
Duplicate attribute
The same attribute name appears twice in one tag, for example <a x="1" x="2"/>. Remove one.
Tips to work faster
- Use Sample first to see all the features at work, including CDATA, a comment and a namespace.
- Beautify, then switch Comments to Remove comments when you only want the data.
- Sort attributes on both versions of a file before you put them into the Text Diff Checker.
- Check the Size line after minifying; a file that is already compact will barely shrink.
Related tools
- XML to JSON: turn a document into JSON for a web app. The guide is at XML to JSON: the complete guide.
- JSON to XML: go the other way, with its own guide.
- XML Sitemap Validator: check a sitemap against the rules search engines use.
- JSON Formatter: the same idea for JSON.
Quick checklist
- Beautify to read, Minify to send.
- Fix errors from the top: one mistake often causes the next.
- Escape
&and<in text and attribute values. - Remember it checks syntax only, not a schema.
- Keep your original file; the formatter is for reading and tidying.



