This free XML formatter online takes unreadable, minified, or badly indented XML and rewrites it with clean structure, so you can actually see how your document nests. Paste your XML into the input pane, click Format XML, and the tidied version appears alongside it, ready to copy or download.
It also validates before it formats. If your XML will not parse, you get the parser’s error message and the line and column where it failed, rather than a scrambled result and a false success message. And everything happens inside your browser: the XML you paste is not uploaded to our server.
What Does an XML Formatter Do?
An XML formatter takes a document with missing line breaks or inconsistent indentation and rewrites it so that every element sits at the correct depth. The same job is often called beautifying or pretty-printing. Machines are perfectly happy reading XML crammed onto a single line, but people are not, and a nesting mistake is nearly impossible to spot without indentation.
Formatting changes presentation only. Element names, attributes, values, and document order are untouched, and any element that holds text, CDATA, or xml:space=preserve is kept exactly as written. Only the whitespace between nested elements changes, so the formatted file carries the same data as the original. If you are new to the format itself, MDN’s introduction to XML is a good primer.
How to Format XML Online
- Paste your XML into the input pane at the top of this page. No account is required. The tool sets no size limit, but very large documents take longer to format, and nesting deeper than 2,000 levels is rejected.
- Click Format XML. Your XML is parsed and checked first. If it is well-formed, the indented version appears in the output pane.
- Read the result. The output pane is read-only, and your original stays in the input pane, so you can compare the two or edit and re-run without losing anything.
- Copy or download. Copy to Clipboard sends the formatted XML straight to your clipboard, and Download saves it as formatted.xml.
If the XML cannot be parsed, no formatted output is produced. Instead you get the parser’s error message, which is the subject of the next two sections.
Formatting Runs in Your Browser
Formatting and validation both run entirely in client-side JavaScript. Nothing you paste is sent to a server, and once this page has loaded the tool keeps working even if you go offline. The validation itself uses the browser’s built-in DOMParser, which is the same XML parser your browser uses to load XML documents.
This is worth checking before you paste anything anywhere. XML in the real world is rarely just data: SOAP payloads, application config files, and API responses routinely carry API keys, connection strings, tokens, and customer records. If a tool does not tell you where your data goes, assume it leaves your machine.
Why Your XML Is Invalid (and How to Fix It)
When the parser rejects your XML, the message it returns is precise but not always friendly. Here are five common failures, the error text Chrome shows for each (other browsers word some of them differently), and how to fix each one.
Opening and ending tag mismatch
Opening and ending tag mismatch: b line 1 and a
A tag was left open, or tags were closed in the wrong order. XML requires strict nesting: a tag opened inside another must close before the outer one does. Check that every opening tag has a matching closing tag, and that <a><b></b></a> nesting is respected rather than <a><b></a></b>.
xmlParseEntityRef: no name
xmlParseEntityRef: no name
An ampersand appears as a bare character. In XML the ampersand starts an entity reference, so a literal one has to be written as &. The other reserved characters have entities as well: use < for a less-than sign, > for greater-than, " for a double quote, and ' for an apostrophe inside attribute values.
Extra content at the end of the document
Extra content at the end of the document
There is more than one root element. An XML document may contain exactly one outermost element, so two sibling elements at the top level will always fail. Wrap them in a single parent element and the document parses.
Start tag expected
Start tag expected, '<' not found
The input does not begin as XML at all. This usually means plain text or JSON was pasted by mistake, or that a stray character sits before the opening tag. Check the very start of your file for invisible characters such as a zero-width space.
Case mismatch between tags
XML is case-sensitive, so <Name> and </name> are two different tags and will report as a mismatch. Unlike HTML, there is no forgiveness here: opening and closing tags must match exactly, character for character.
XML Formatting Rules Worth Knowing
Most invalid XML breaks one of a short list of rules. Well-formed XML always has:
- Exactly one root element wrapping everything else in the document.
- Every tag closed, either with a closing tag or as a self-closing element such as
<br />. - Correct nesting, with inner elements closing before their parents.
- Case-sensitive matching between each opening and closing tag.
- Escaped special characters: any ampersand or less-than sign used as text, plus a quote character inside an attribute value that is wrapped in the same quote.
- Quoted attribute values, using single or double quotes consistently.
An XML declaration such as <?xml version="1.0" encoding="UTF-8"?> is optional but recommended, since it states the encoding explicitly. The full rules are defined in the W3C XML specification. Note that this tool checks whether your XML is well-formed, which is different from validating it against a schema such as an XSD or DTD.
When You Need Formatted XML
- Reading API and SOAP responses. Web services often return XML as one continuous line; formatting is a quick way to find the field you need.
- Reviewing configuration files. pom.xml, web.config, and AndroidManifest.xml are far easier to audit when the hierarchy is visible.
- Inspecting sitemaps and RSS feeds. Both are XML, and a formatted view makes an odd or misplaced entry easy to spot.
- Diffing two XML files. Inconsistent whitespace creates noise in a diff. Format both files first and the real differences stand out.
Related Developer Tools
Working with JSON instead of XML? Our free JSON Formatter does the same job for JSON, including validation and error reporting. Shrinking code for production? The JavaScript minifier strips whitespace and comments from your scripts. And for a deeper walkthrough of XML structure and common mistakes, read our guide to formatting and validating XML online.