Free XML Formatter
Indent or minify an XML document and find the exact tag, attribute or character that keeps it from being well-formed.
What is a XML Formatter?
An XML formatter checks that an XML document is well-formed and lays it out with one element per line and consistent indentation. Well-formed means every element is closed, nested correctly and quoted properly, the baseline every XML parser requires.
This tool parses XML with fast-xml-parser, a pure JavaScript parser, and rebuilds it either indented with two spaces or minified onto one line. Declarations, comments, CDATA sections and entity references such as & are kept as written. It doesn’t validate against a schema or DTD; it tells you whether the document parses, and if not, where and why.
Key Features
The Failing Tag Named for You
A mismatched closing tag is reported with both names and the position, such as which element closed while another was still open. You fix the right line first time.
Pretty or Minified Output
Pretty puts each element on its own indented line for reading and diffs. Minify strips the whitespace between elements for smaller payloads.
Comments and CDATA Kept
Formatting keeps the XML declaration, comments and CDATA sections instead of throwing them away, so the document still says what it said.
Entities Left Untouched
References such as & and © stay exactly as written, so formatting never changes the meaning of your text.
Documents Stay on Your Device
Parsing runs in the browser, so invoices, configuration files and API responses you paste aren’t uploaded.
Checks as You Type
The document is re-checked on every keystroke, so you can fix one error and immediately see whether the next one appears. Large files of a few hundred kilobytes still respond quickly.
Perfect for everyone
- Backend developers reading SOAP and API responses
- SEO specialists checking sitemaps and feeds
- Front-end developers tidying SVG files
- Integration engineers debugging EDI and invoice XML
How to Use the XML Formatter
Paste a document, pick Pretty or Minify, and fix anything it flags.
Paste the XML
Paste a full document such as a feed, sitemap, SVG or API response. Fragments work too, as long as they have a single root element.
Choose Pretty or Minify
Pretty indents nested elements by two spaces each. Minify removes the whitespace between elements but leaves text content alone.
Read the Verdict
A green Well-formed footer means every parser will accept the structure. A red one comes with a line, column and the exact tag or character to fix.
Copy or Download the Result
Copy the formatted XML into your editor or ticket, or download it as an .xml file ready to commit.
Documents Run Through This Tool
These are documents we formatted here, with the exact output or the exact error the tool returned. The broken ones are the mistakes we see most in real files.
“<note id="1"><to>Ada</to><body>Hello</body></note>”
“<?xml version="1.0" encoding="UTF-8"?><!-- invoice 42 --><invoice><total currency="EUR">99.50</total></invoice>”
“<rss version="2.0"><channel><title>News & notes</title></channel></rss>”
“<order id="42"> <item qty="2">Ink</item> </order>”
“<note><to>Ada</note>”
“<p>Fish & Chips</p>”
“<a b=1></a>”
“<a></a><b></b>”
“<1a/>”
“<a x="1" x="2"/>”
What Makes XML Well-Formed
The XML 1.0 specification lists the rules every document must follow before any parser accepts it. These are the ones real files break.
Exactly One Root Element
Everything must sit inside a single top-level element. Two siblings at the top, as in a concatenated file, make the document invalid.
“Can an XML document have two root elements?”
Every Element Is Closed
Each start tag needs a matching end tag, or the element must be self-closing with a slash before the final bracket. HTML’s optional closing tags don’t exist in XML.
“Is an unclosed paragraph element allowed?”
Elements Nest Properly
An element opened inside another must close before its parent does. Overlapping elements are the most common structural error.
“Which element must close first?”
Names Are Case-Sensitive
Item and item are different element names, so a start tag and end tag that differ only in case don’t match.
“Does Item close item?”
Attribute Values Are Always Quoted
Every attribute needs a value in single or double quotes. Bare values and value-less attributes from HTML aren’t valid XML.
“Is width=24 valid in XML?”
Attributes Appear Once per Element
The same attribute name can’t be repeated on one element. Repeat the element instead if you need several values.
“Can an element carry id twice?”
Ampersands Start References
An ampersand in text must begin an entity reference such as &. A bare ampersand, common in company names, breaks the document.
“How is a literal ampersand written?”
Less-Than Signs Start Markup
A less-than sign in text is read as the start of a tag, so write it as <, or wrap the text in a CDATA section.
“How is a literal less-than sign written?”
Element Names Have Rules
Names start with a letter or underscore, never a digit, and contain no spaces. Names starting with xml in any case are reserved.
“Is 2024-report a valid element name?”
Only Five Entities Are Predefined
XML knows &, <, >, " and ' without a DTD. HTML names such as need a numeric reference instead.
“Is predefined in XML?”
XML Formats This Handles
Many everyday file types are XML underneath, and all of them must be well-formed first.
RSS and Atom Feeds
A single bare ampersand in an item title makes feed readers drop the whole feed. Check feeds here before publishing them.
XML Sitemaps
Search engines reject sitemaps that aren’t well-formed. Validate a sitemap after generating it, especially when URLs contain query strings with ampersands.
SVG Images
SVG is XML, so an unquoted attribute that browsers tolerate inline can break the file elsewhere. Minify an SVG to trim the whitespace editors add.
SOAP and Legacy APIs
SOAP requests and responses arrive as one long line. Pretty makes the envelope, header and body readable when debugging an integration.
Office Documents
DOCX, XLSX and PPTX files are zip archives of XML parts. Paste a part such as document.xml to inspect its structure.
E-Invoicing and EDI
Formats such as UBL and ISO 20022 are XML. Well-formedness is the first check before validating against their schemas.
Android and Maven Files
Android layouts, AndroidManifest.xml and Maven pom.xml are plain XML. A missing closing tag in one of them stops the build with a far less helpful message than the one here.
GPX and KML Map Data
GPS tracks from watches and route planners are exported as GPX or KML, both XML. Format a track file to read its waypoints or to find where an export was cut short.
XML Mistakes That Break Parsers
Each of these turns a document that looks fine into one no parser accepts.
Company Names With Ampersands
Data such as Johnson & Johnson pasted into XML text breaks it. Escape it as & when building XML, ideally with a library rather than by hand.
HTML Habits in XML
Unclosed line breaks, unquoted attributes and named entities like are fine in HTML but not in XML. XHTML, SVG and feeds follow the XML rules.
Concatenated Documents
Joining two XML files produces two roots and a second declaration in the middle. Wrap the parts in a parent element instead.
Hand-Edited Closing Tags
Renaming an element’s start tag but not its end tag leaves a mismatch. The error names both tags, so search for the one it reports.
Byte Order Marks and Declarations
The XML declaration must be the very first thing in the file. A stray space or invisible character before it makes some parsers reject the file.
Assuming Well-Formed Means Valid
Passing here doesn’t mean a document matches its schema, for example a sitemap with a missing loc element. Run a schema validator for that second check.
Use CDATA for Code Samples
When text contains many ampersands and less-than signs, such as an embedded script or SQL query, wrap it in a CDATA section instead of escaping each character.
Wrong Encoding Declaration
A declaration that says ISO-8859-1 on a file saved as UTF-8 makes accented characters come out garbled in strict parsers. Make the encoding attribute match how the file was actually saved.
Everyday XML Jobs
XML still runs feeds, invoices, office files and integrations, so it often needs a quick look.
Reading an API Response
Paste a one-line XML response from a SOAP or legacy REST API and pretty-print it to see the structure and values.
Fixing a Broken Feed
When a podcast or RSS feed stops updating in readers, paste it here to find the stray character or unclosed element.
Checking a Sitemap Before Submitting
Validate a generated sitemap before submitting it in Search Console, so crawlers don’t reject the file.
Trimming SVG Files
Minify SVG icons exported from design tools to remove indentation before inlining them in HTML or CSS.
Reviewing Configuration Files
Maven pom.xml, Android layouts and .NET config files are XML. Format one to review a diff or find a misplaced element.
Debugging E-Invoices
Format an invoice XML before checking it against the UBL or Peppol rules, so each field is on its own line.
Preparing Test Fixtures
Minify an XML fixture to keep a test file short, or pretty-print one to make a failing assertion readable.
Making XML Diffs Readable
Two minified versions of the same file produce a one-line diff that shows nothing. Pretty-print both first, then compare them line by line.