How to Fix XML Parsing Errors
XML parsers are strict by design, so most errors come from four causes: something before the XML declaration, usually a byte-order mark or a blank line; a bare ampersand that was never escaped; tags that do not close in the order they opened; and an HTML entity such as nbsp that XML does not define. Each has a precise fix.
XML Validator
Check that an XML document is well-formed.
XML has no error recovery. An HTML parser will make a reasonable guess about a missing closing tag; an XML parser stops. That strictness is deliberate — it is what makes XML safe for document interchange — but it means a single stray byte invalidates the whole file.
The error messages are unusually literal once you know the vocabulary. "Prolog" means everything before the root element, so an error there is about the very start of the file, not about your data.
Step by step
-
Check what comes before the declaration
Content is not allowed in prolog means there are bytes before <?xml. Usually this is an invisible UTF-8 byte-order mark, a blank line, or a PHP warning printed above the output. Nothing at all may precede the declaration.
-
Escape bare ampersands
A raw & is the start of an entity reference, so a URL such as ?a=1&b=2 inside an element breaks parsing. Write & instead. This is the single most common cause in feeds and sitemaps.
-
Match every tag, in order
XML requires strict nesting: <a><b></b></a>, never <a><b></a></b>. Empty elements must self-close as <br/> rather than <br>. A formatter that re-indents the document makes an unclosed tag obvious immediately.
-
Replace HTML entities XML does not know
XML defines only five entities: &, <, >, " and '. Anything else — , ©, — — is undeclared and rejected. Use the numeric form such as  , or the literal character in a UTF-8 document.
-
Validate the whole file, not a fragment
Paste the complete document into a validator. A fragment will report misleading errors because a well-formed XML document must have exactly one root element, and a snippet usually does not.
Example
Two errors in three lines: a bare ampersand and an undeclared HTML entity.
Rejected
<item>
<link>https://example.com/?a=1&b=2</link>
<title>Tea Coffee</title>
</item>
Well-formed
<item>
<link>https://example.com/?a=1&b=2</link>
<title>Tea   Coffee</title>
</item>
Frequently asked questions
What does "Content is not allowed in prolog" mean?
Why is a plain ampersand invalid in XML?
Can I use in XML?
Is XML case-sensitive?
What is the difference between well-formed and valid?
Tools used in this guide
All tools →- XML Validator Check that an XML document is well-formed. In your browser
- XML Formatter Indent XML so nested documents become readable. In your browser
- XML to JSON Converter Convert any XML document into readable JSON. In your browser
- HTML Entity Encoder and Decoder Escape HTML special characters, or decode entities back. In your browser
Related guides
All guides →- How to Convert XML to JSON Turn an XML document or feed into JSON, and handle the attributes and repeated elements that make it lossy.
- JSON vs XML Why JSON replaced XML for most APIs, and the cases where XML is still the better answer.
- How to Fix Broken Characters in Text Diagnose mojibake, question marks and invisible characters, and repair the text.
Last reviewed .