XML Repair — fix broken XML
Paste XML that will not parse and get a version that does — with a list of exactly what was changed. It closes unclosed tags, escapes bare ampersands, quotes unquoted attribute values, converts HTML-only entities, and wraps a document that has more than one root.
XML Repair
A parser tells you where a document breaks; this tries to fix it. Each repair is a targeted rewrite of a specific, common breakage, and the report below the panes lists every change made plus whether the result now parses. Nothing is guessed silently.
How to use it
- Paste the broken XML into the left pane, or drop the file on it.
- Leave all the repairs on for a first pass — the report tells you what each one did.
- If a repair changed something you did not want changed, untick it and run again.
- Read the last line of the report: it says whether the result is now well-formed.
What each repair does
- Bare ampersands. An
&that does not start a valid entity or numeric reference becomes&. This is the single most common reason a document from a CMS or a database export will not parse. - HTML-only entities. XML defines exactly five named entities.
,—,©and friends are HTML, not XML: known ones are converted to numeric references, unknown ones are escaped so they survive as text. - Unclosed tags. The tag stream is tracked on a stack. A closing tag that does not match the top of the stack closes the elements above it first; anything still open at the end of the document is closed in reverse order. Stray closing tags with no matching open element are dropped.
- Unquoted attribute values.
<a href=/x>becomes<a href="/x">. HTML tolerates unquoted values; XML never does. - Curly quotes. Word-processor quotation marks around an attribute value are replaced with straight ones, which is what the parser requires.
- Multiple roots. A document with two or more top-level elements — concatenated fragments, a log of records — is wrapped in a single element so it becomes a legal document.
- A UTF-8 byte-order mark, junk text before the first element, and illegal control characters are always removed.
What it will not fix
Repairs are textual and conservative, so some breakage is out of scope: a truncated file with the second half missing, a mis-encoded document (Latin-1 bytes labelled UTF-8), a mismatched tag whose intent is genuinely ambiguous, or an unescaped < inside text that could equally be the start of a tag.
When the report's last line still says the document is not well-formed, it also carries the parser's message — that is your next clue.
Check the result before trusting it
Automatic repair changes your data. Closing tags in reverse order, in particular, is a guess about nesting that is right for a truncated document and wrong for a genuinely mis-nested one. Diff the output against the original — the XML diff is the quickest way — before it goes anywhere important.
FAQ
Will it fix mismatched tags like <b><i></b></i>?
It will make the document parse, by closing <i> before </b> and dropping the now-stray </i>. Whether that is the nesting you meant is a judgement only you can make — check the report and the diff.
Why is my &nbsp; now a number?
XML has no . It is converted to  , which every parser understands and which renders identically. Untick fix HTML entities if you would rather see the parse error.
What about an unescaped less-than sign in text?
That is deliberately not repaired. A bare < in text is indistinguishable from the start of a tag, and guessing wrong would corrupt the document. Escape those by hand — the escape tool helps.
Does it preserve comments and CDATA?
Yes. Comments, CDATA sections, processing instructions and the doctype are passed through untouched; only the specific breakages listed above are rewritten.
Is the file uploaded anywhere?
No. Every repair runs in your browser, so a broken export full of customer data stays on your machine.
Related tools
- XML Validator — find out exactly where a document breaks
- XML Formatter — re-indent once the document parses
- XML Escape / Unescape — for text you need to escape by hand
- XML Diff — compare the repaired file against the original
- Namespace Remover — strip prefixes that make XPath awkward
Privacy
100% client-side. Repairs are textual rewrites performed in the page. See the privacy policy.