XML Formatter
Pretty-print, minify and validate XML. Errors are pinned to the exact line and column with the reason and the fix, and the document can be browsed as a collapsible element tree.
How to Use
- Paste XML into the box or drop a file (XML, SVG, RSS, sitemap, config). It is checked as you type.
- Choose Pretty to indent it, Minify to remove the whitespace between tags, or Tree to fold and unfold elements.
- Pick a 2-space, 4-space or tab indent, and tick Strip comments if you want them gone.
- If the XML is not well-formed, the result shows the exact line and column with a caret under the problem, the reason, and how to fix it.
- Read Show Work for every check that passed, then press Copy result or Download .xml.
Worked Example
A 253-byte book catalogue arrives on one line. The checks: the <?xml version="1.0" encoding="UTF-8"?> declaration is the very first thing; there is one root, <catalog>; 7 start tags meet 7 end tags in the right order; all 5 attributes are quoted; the one entity, ', is one of the five XML predefines. It is well-formed.
Pretty-printing puts the root at column 1 and adds 2 spaces per level, so <book> (level 2) gets 2 spaces and <title> (level 3) gets 4. Elements that hold only text stay on one line. The result is 11 lines and 287 bytes, 34 bytes (13.4%) more than the input:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101" lang="en">
<title>XML Developer's Guide</title>
<price currency="USD">44.95</price>
</book>
<book id="bk102">
<title>Midnight Rain</title>
<price currency="USD">5.95</price>
</book>
</catalog>
Minify does the reverse: the indented 2-URL sitemap preset drops from 288 bytes to 254 when the whitespace between tags is removed.
The common mistake: closing tags in the wrong order. In <note><to>Tove</to><from>Jani</frm></note> the parser is inside <from> (opened at column 20) when it meets </frm> at line 1, column 30, so the whole document is rejected there — XML parsers must stop at the first error rather than guess, unlike browsers reading HTML. Fixing the one typo makes it well-formed.
Show Work
Well-Formedness Rules
Where XML Came From
XML is a simplified subset of SGML, the document markup standard published as ISO 8879 in 1986. A W3C working group chaired by Jon Bosak of Sun Microsystems, with Tim Bray, Jean Paoli and C. M. Sperberg-McQueen as editors, cut SGML down to something a small program could parse, and XML 1.0 became a W3C Recommendation on 10 February 1998. Its strictest decision was that a parser must stop at the first well-formedness error instead of guessing, the opposite of how browsers treat HTML.
Namespaces followed in January 1999, letting one document mix vocabularies such as soap: and m:. XML went on to carry SOAP web services, RSS 2.0 feeds, SVG graphics, XML sitemaps and the Office Open XML formats inside every .docx and .xlsx (ECMA-376, 2006). JSON has since taken over most new web APIs, but XML is still everywhere in documents, feeds and enterprise systems.
About This Tool
This tool checks XML with its own parser, which reports the first well-formedness error by line and column with the reason and a fix — mismatched or unclosed tags, unquoted or repeated attributes, undefined entities, undeclared namespace prefixes, a second root, a misplaced declaration. The browser’s built-in XML parser runs as a second opinion. Well-formed documents can be pretty-printed with syntax highlighting, minified, or browsed as a collapsible element tree.
Everything runs in your browser; documents and files are never uploaded. Documents up to 5 MB are handled, and schema validation against a DTD or XSD is not attempted.
Related tools: JSON Formatter, YAML / JSON Converter, and Minifier / Beautifier.
Frequently Asked Questions
What is the difference between well-formed and valid XML?
Well-formed means it follows the XML syntax rules: one root element, every tag closed and properly nested, attribute values in quotes, and & and < escaped. This tool checks exactly that. Valid also means it matches a schema (a DTD or XSD) that says which elements may appear where. Schema checks need the schema file, so use xmllint --schema or your IDE for those.
Why does break my XML?
XML predefines only five entities: &, <, >, " and '. HTML names such as or © are unknown unless a DOCTYPE declares them. Write the number instead:   for a non-breaking space, © for ©.
Will pretty-printing change my data?
Only whitespace. Indentation is added between elements, and text in an element that holds only text is trimmed, so x becomes x. Attributes, CDATA sections, comments and processing instructions are kept exactly as written, and anything inside an element marked xml:space="preserve" is not touched at all.
Can it format HTML?
Only XHTML. Ordinary HTML is not XML: and <img> are never closed, attributes may be unquoted and is everywhere, so the first of those stops the check with its line and column. Use the Minifier / Beautifier in HTML mode for normal web pages.
How much smaller does Minify make XML?
It removes only the whitespace between tags, so the saving is the indentation. The sitemap preset, 2 URLs indented with 2 and 4 spaces, goes from 288 bytes to 254, which is 34 bytes or 11.8% smaller. Text inside elements is kept exactly, and gzip on the server usually saves far more than minifying.
How do I use the XML Formatter?
Simply type your numbers and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.
Is it free? Does it work without internet?
Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.
Where does my data go?
Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.
Common Use Cases
SOAP and API debugging
Format a one-line SOAP response and open it in Tree view: the soap:Envelope, soap:Body and m:GetPrice levels fold separately, and an undeclared prefix is reported by line and column.
RSS and Atom feeds
Check a podcast or blog feed before publishing. A bare & in a title or a stray is the usual reason a feed reader rejects it.
Sitemaps
A sitemap may hold up to 50,000 URLs and 50 MB uncompressed. Validate it here before submitting, then minify it to trim the indentation.
Config files
Maven pom.xml, .NET .csproj and Android manifests: drop the file, find a mismatched tag by its line number, and copy back a cleanly indented version.
SVG and Office files
SVG icons are XML, and a .docx or .xlsx is a ZIP of XML parts such as word/document.xml. Pretty-print them to see their structure.
Last updated: