XML Formatter — Format, Validate & Minify XML Online Free
An XML formatter takes messy, single-line XML and rewrites it with clean, consistent indentation so you can read the structure at a glance. This free XML formatter also validates your document and can minify it to a single line — all in your browser, with nothing uploaded anywhere.
What Is an XML Formatter?
An XML formatter is a tool that takes XML markup and rewrites it with consistent line breaks and indentation. XML files from APIs, sitemaps, and config files often arrive as one long line with no line breaks at all, which makes them almost impossible to read. A formatter puts each element on its own line and indents nested elements, so the parent-child structure becomes obvious. This page is a free XML formatter that also checks whether your document is well-formed and can shrink it back to a single line when you need the smallest possible file.
Formatting never changes what your XML means. It only changes whitespace between elements — the tags, attributes, and text stay exactly the same. That is why you can safely format a sitemap or an API response, check it, and then minify it again before sending it back.
How to Format XML Online
- Paste your XML into the input box at the top of this page, or click "Load sample" to try it with a book catalog example.
- Choose your indent. Pick 2 spaces, 4 spaces, or a tab — whichever matches your project's style.
- Click "Format XML". The formatted document appears in the output box, together with the original size, the new size, and the line count.
- Read the result. If your XML is invalid, the tool shows the exact error from the XML parser, with the line and column number when the parser reports one, so you can find the problem fast.
- Copy or download. Use "Copy result" to paste the formatted XML into your editor, or "Download .xml file" to save it.
- Minify when you are done. Click "Minify XML" to collapse the document back to a single line for production use.
Format vs Minify vs Validate
These three jobs sound similar, but they do different things. This XML formatter does all three, so it helps to know which button to press.
| Job | What it does | When to use it |
|---|---|---|
| Format (beautify) | Adds line breaks and indentation so the structure is readable | When you need to read, debug, or edit XML from an API, a sitemap, or a log file |
| Minify | Removes all whitespace between tags and collapses the document to one line | Before sending XML to production, an API, or a file where size matters |
| Validate | Checks the document is well-formed — every tag closed, one root element, no bad characters | Before publishing a sitemap or config file, and whenever a parser rejects your XML |
Formatting and minifying are exact opposites: format a minified file to read it, then minify it again to ship it. Validating is the safety check that should come first — a document that is not well-formed cannot be formatted reliably, so this tool validates before it formats or minifies and tells you what is wrong instead of guessing.
When to Use an XML Formatter
- Sitemaps. A Blogger or WordPress sitemap is an XML file listing every page on a site. When a search engine reports a sitemap error, formatting the file makes the broken line easy to find. Search Console errors almost always point at a line number, and a formatted file has real lines to match.
- RSS and Atom feeds. Blog and podcast feeds are XML. If a feed reader stops updating, format the feed and look for an unclosed tag or a stray
&that was never written as&. - API responses. Older APIs — and many enterprise ones — still return XML, often as a single line. Formatting the response lets you see the fields and nesting instead of scrolling sideways through thousands of characters.
- SOAP messages. SOAP web services wrap every request and response in an XML envelope. A formatter turns a wall of text into a readable request you can actually debug.
- Android layouts and config files. Android layout files, Maven
pom.xmlfiles, .NET project files, andweb.configfiles are all XML. Formatting one after a bad merge makes the conflict damage visible in seconds. - SVG images. SVG is XML too. Formatting an exported SVG shows the groups, paths, and attributes so you can edit the image by hand instead of re-exporting it.
XML Formatter vs JSON Formatter
XML and JSON solve the same problem — moving structured data between systems — but they look very different. If you work with APIs, you will meet both, and each has a matching formatter on AIToolsForBloggers.
| Feature | XML | JSON |
|---|---|---|
| Basic unit | Elements with opening and closing tags, e.g. <title>...</title> | Key-value pairs and arrays, e.g. "title": "..." |
| Attributes | Yes — <book id="bk101"> | No — everything is a value |
| Comments | Yes — <!-- ... --> | No — JSON has no comments |
| Typical size | Larger — closing tags repeat every name | Smaller — no closing tags |
| Common uses | Sitemaps, RSS feeds, SOAP, SVG, config files | REST APIs, app settings, data exchange |
| Tool on this site | This XML formatter | JSON Formatter |
Neither format is "better" in general — it depends on what the other side expects. A sitemap must be XML, because that is what search engines read. A modern REST API usually speaks JSON. Use the XML formatter for the first kind of job and the JSON Formatter for the second.
Worked Example
Here is a real example, formatted with this page's own logic using the 2-space indent. The byte counts below were produced by running the formatter on this exact input — nothing is estimated.
Before — 463 bytes, 3 lines:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Book catalog sample -->
<catalog version="2.0"><book id="bk101" lang="en"><title>XML Guide</title><author>Jane Doe</author><price currency="USD">29.99</price><description><![CDATA[Learn <XML> the easy way & enjoy!]]></description><inStock /></book><book id="bk102"><title>JSON Basics</title><author>John Smith</author><price currency="USD">19.99</price><description>Short guide</description><inStock /></book></catalog>
After — formatted, 538 bytes, 20 lines:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Book catalog sample -->
<catalog version="2.0">
<book id="bk101" lang="en">
<title>XML Guide</title>
<author>Jane Doe</author>
<price currency="USD">29.99</price>
<description>
<![CDATA[Learn <XML> the easy way & enjoy!]]>
</description>
<inStock />
</book>
<book id="bk102">
<title>JSON Basics</title>
<author>John Smith</author>
<price currency="USD">19.99</price>
<description>Short guide</description>
<inStock />
</book>
</catalog>
Notice what survived the formatting: the XML declaration stays on the first line, the comment stays a comment, the CDATA section keeps its <XML> and & untouched, and the self-closing <inStock /> tags stay self-closing. Only the whitespace between elements changed.
Frequently Asked Questions
Is my XML uploaded anywhere?
No. This XML formatter runs entirely in your browser using the browser's own XML parser. Your document never leaves the page, is never sent to a server, and is never stored. You can disconnect from the internet after the page loads and the formatter will still work.
Why does the formatter say my XML is invalid?
The most common causes are an unclosed tag (<title> with no </title>), mismatched tags (<book>...</books>), more than one root element, or a bare & in text that should be written as &. The error box shows the parser's exact message with the line and column number, so start at that spot. Fix one error at a time and validate again — parsers usually report only the first problem they find.
What is the difference between formatting and minifying XML?
Formatting adds whitespace (line breaks and indentation) to make XML readable by humans; minifying removes whitespace to make the file as small as possible for machines. The data is identical either way. Format when you need to read or fix a file, minify when you need to ship it.
Can this tool fix broken XML for me?
No — and no formatter should try. Guessing where a missing closing tag belongs can silently change the meaning of your document. This tool tells you exactly what is wrong and where, and you fix it in the original. Once the document is well-formed, formatting and minifying work in one click.
Does it handle comments, CDATA, and entities?
Yes. Comments (<!-- ... -->) are kept as comments, CDATA sections (<![CDATA[...]]>) are copied byte-for-byte so the markup inside them is never touched, and entities such as &, <, and " are preserved. One thing to watch: an undefined entity such as is not valid in plain XML — only the five built-in entities (&, <, >, ", ') are allowed unless your document defines the others.
Why is DOCTYPE rejected?
This formatter refuses documents containing a DOCTYPE declaration. A DOCTYPE can define external entities, and processing those can make a parser read local files or contact other servers — a classic XXE (XML External Entity) attack. For a browser tool, the safe choice is to refuse the whole declaration rather than guess which parts are harmless. If your file has a DOCTYPE, remove that one line and format the rest.