How to format XML
- Paste your XML into the XML input box, or press Upload .xml to open a file. RSS/Atom feeds, SOAP responses, sitemaps, SVG and config files all work.
- It is formatted as you type. Choose 2 spaces, 4 spaces or Tab under Indent.
- Press Minify to strip whitespace instead, or Validate to check well-formedness without reformatting.
- Press Copy or Download to take the result with you. Ctrl+Enter (Cmd+Enter on a Mac) re-runs the last action.
XML pretty print example
A one-line XML document is hard to scan:
<catalog><product id="BK-001"><name>Notes on the Analytical Engine</name><price>24.50</price></product></catalog>Formatted with 2 spaces, each element gets its own line and nesting is indented:
<catalog>
<product id="BK-001">
<name>Notes on the Analytical Engine</name>
<price>24.50</price>
</product>
</catalog>Attribute order (id="BK-001") is kept exactly as written, and elements holding only text, like <name> and <price>, stay on one line instead of being split further.
XML minify: strip it down for transport
Minifying removes every insignificant space, tab and line break between tags. The pretty printed example above shrinks from 130 to 113 characters:
<catalog><product id="BK-001"><name>Notes on the Analytical Engine</name><price>24.50</price></product></catalog>Use minified XML for API payloads and anywhere size matters; use formatted XML for code review and debugging. Both parse to the same document.
How to validate XML (well-formedness)
Every time you type, paste or press Validate, the XML is checked with a hand-written parser built for this tool (not a browser DOM parser, so it stays consistent across browsers and reports a location even when the source has none). Valid XML shows a summary like "root <catalog>, 4 elements, nested 3 deep." Invalid XML shows:
- the line and column of the first problem;
- a plain-English explanation and, where it helps, what to write instead;
- a snippet of the lines around the error with the problem character highlighted, and a Show in input button that jumps to it.
This validator checks well-formedness (are the tags balanced and the syntax legal), not a schema: it will not tell you that an element is in the wrong place according to an XSD or DTD, only that the XML itself parses.
Why is my XML not well-formed? Common errors and fixes
These are the errors this validator reports for the mistakes we see most often:
- Unclosed tag:
<order>↵ <item>Pen↵</order>
line 3, column 3: Mismatched closing tag: expected </item> (opened at line 2) but found </order>. - Mismatched closing tag:
<order>↵ <item>Pen</item2>↵</order>
line 2, column 14: Mismatched closing tag: expected </item> (opened at line 2) but found </item2>. - Attribute value not quoted:
<item id=42>Pen</item>
line 1, column 10: The value of attribute "id" must be in quotes ("…" or '…').
Other frequent causes: a stray & that should be &, more than one root element, and a DOCTYPE that appears twice or after the root element.
What the formatter preserves: comments, CDATA, PIs, attribute order
Many "XML formatters" parse your document into a generic tree and rebuild it, which can silently reorder attributes, drop comments, or merge things that were kept separate. This tool works from the tokens of your original text instead, so it keeps:
- Comments (
<!-- … -->), on their own line, wherever they appeared; - CDATA sections (
<![CDATA[ … ]]>), with their contents untouched and undecoded; - Processing instructions like
<?xml-stylesheet …?>, including the<?xml … ?>declaration; - Attribute order and quote style (
"or'), exactly as written; - Mixed content — text next to inline elements — left exactly as written, rather than reflowed.
For example, this article mixes inline markup with an <em> tag, a comment, and a CDATA block holding code with a raw & and <:
<article lang="en">
<!-- intro paragraph -->
<p>Ada Lovelace wrote notes on <em>Babbage's</em> Analytical Engine.</p>
<code><![CDATA[if (a < b) { return a & b; }]]></code>
</article>Formatted, the comment and the <code> element each get their own line, but the sentence inside <p> is left exactly as written because it mixes text and an element:
<article lang="en">
<!-- intro paragraph -->
<p>Ada Lovelace wrote notes on <em>Babbage's</em> Analytical Engine.</p>
<code><![CDATA[if (a < b) { return a & b; }]]></code>
</article>XML formatter vs beautifier vs validator vs minifier
- XML validator: answers "is this well-formed XML?" and points to the first error.
- XML formatter or beautifier: rewrites well-formed XML with indentation, also called pretty print. It validates first, because broken XML cannot be reformatted.
- XML minifier: the reverse — removes whitespace to make the document smaller.
- None of these check the XML against a schema (XSD/DTD); they check the syntax only.
Security: DOCTYPE declarations and entities
XML parsers that expand entities can be tricked into reading local files (XXE) or into exponential memory blow-ups ("billion laughs"), both through a crafted <!DOCTYPE>. This formatter never expands any entity, standard or custom: it treats &, é and a custom &writer; the same way — as text to check for well-formedness and pass through unchanged. Here a DOCTYPE declares a custom entity, and it is echoed back exactly as written, never expanded:
<!DOCTYPE note [<!ENTITY writer "Ada">]>
<note><to>Babbage</to><from>&writer;</from></note><!DOCTYPE note [<!ENTITY writer "Ada">]>
<note>
<to>Babbage</to>
<from>&writer;</from>
</note>And because everything runs in your browser, the XML never leaves your device in the first place.
More developer tools
- XML to JSON converter: turn XML into JSON, with attributes, repeated elements and CDATA handled.
- JSON formatter & validator: the same pretty print, minify and validate workflow for JSON.
- HTML viewer: paste HTML and see it rendered live in a sandboxed preview.
Frequently asked questions
How can I format an XML file?
Paste it into the box above, or press "Upload .xml" to open a file from your computer. It is pretty printed as you type, with 2 spaces, 4 spaces or a tab under Indent. Press Copy or Download to take the result with you; nothing is uploaded to a server.
How do I convert XML to a readable format?
That usually means pretty printing it: adding line breaks and indentation so nested elements are easy to scan. This tool does exactly that, and unlike many online formatters it never parses your XML into a generic object first, so element order, attribute order, comments and CDATA all come back exactly as you wrote them.
How do I beautify XML in Notepad?
Plain Notepad has no XML formatter. Notepad++ has one built in (plugins menu, or Edit > Line Operations), and VS Code formats an open .xml file with Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac) if the XML extension is installed. For a quick one-off with no install, paste the file here instead.
What is the best free XML editor?
For quick formatting and validation with nothing to install, a browser tool like this one is fastest. For heavier editing — XPath queries, schema (XSD) validation, XSLT — a dedicated editor such as Visual Studio Code (with an XML extension), Oxygen XML or Notepad++ goes further, at the cost of an install.
What is the difference between an XML formatter and an XML validator?
A validator checks that XML is well-formed (every tag opened is closed, in the right order, attributes are quoted) and reports where it breaks. A formatter re-indents XML so it is easy to read. A formatter has to check well-formedness first, since broken XML cannot be reformatted, so this tool does both: invalid XML gets a line and column, valid XML gets formatted.
Why is my XML not well-formed?
The most common causes are a tag that is opened but never closed, a closing tag with the wrong name (mismatched tags), an attribute value without quotes, more than one root element, and a stray "&" that should be "&". The validator points at the exact line and column of the first problem and explains it in plain English.
Does the formatter change my data?
No. Whitespace between tags (indentation) is the only thing added or removed. Attribute order, attribute quote style, comments, CDATA sections, processing instructions and any text are kept exactly as written — the formatter works from the original characters, not from a parsed object that would lose that detail.
What happens to mixed content, like text next to inline elements?
When an element mixes text with child elements, such as a <p> with an <em> in the middle of a sentence, reindenting could change where the visible spaces fall. This tool leaves that content exactly as written instead of reflowing it, and only adds indentation to elements that hold nothing but child elements.
Is it safe to paste XML with a DOCTYPE?
Yes. The DOCTYPE is kept in the output so you can see it, but it is never parsed or acted on: no internal or external entity it declares is ever expanded. That rules out the classic XML attacks (XXE, "billion laughs") by construction, not by filtering.
Can it format large XML files?
Yes, multi-megabyte files format in under a second on a typical laptop. The page stays responsive while you type because large input is checked after a short pause. Use Upload for a file instead of pasting it, and Download to save the formatted result.
Is my XML uploaded anywhere?
No. Formatting, minifying and validation all run in your browser with JavaScript; nothing you paste or upload is sent to a server, logged or saved. Only your indent and auto-format settings are remembered on your device.