How To Fix XML Parsing Error in Blogger

Mostly when you insert Facebook, Google Adsense, or other JavaScripts into your blogger template editor, You come to see an XML Parsing error that says "The reference to entity "version" must end with the ';' delimiter.a Because blogger blogs are in XHTML codded and XML is quite strict in following correct syntax formatting than HTML.

How To Fix XML Parsing Error in Blogger
XML is PCDATA (Parsed Character Data) by default which means that XML parsers will normally parse all the text in a document. As a result when we insert JavaScript inside blogspot templates, all script inside the JavaScript tags is treated as text and due to the presence of some illegal special characters like "<" , ">" and "&" , you often face the following error:
Error parsing XML, line 1458, column 64: The reference to entity "version" must end with the ';' delimiter.

what are the special characters in XML that cause errors?

XML is a human-readable form of textual data. It parses all the text in a document and gives errors for the following 5 special characters:

(<)  - less than

(&) - ampersand

(>) - greater than

(")  - double-quote

(')  - apostrophe or single-quote

The following three are more crucial:
"<" will generate an error because the parser interprets it as the start of a new element.
">" will generate an error because the parser interprets it as the end of a start tag or an end-tag
"&" will generate an error because the parser interprets it as the start of a character entity.

Read Also: Top 12 Google SEO Ranking Factors

how to fix xml parsing error in blogger

XML errors can be avoided by using two methods:

Use CDATA
Escape HTML entities


1. Use CDATA

The term CDATA refers to (Unparsed) Character Data which is used about text data that should not be parsed by the XML parser. To avoid errors, all script code is enclosed inside a CDATA section. Everything inside a CDATA section including the 5 special characters is ignored by the parser.

A CDATA section starts with "<![CDATA[" and ends with "]]>":

Next time when you add your Facebook code, enclose it inside CDATA as shown below:
<script>
//<![CDATA[
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

//]]> </script>
All your script code will exist inside the CDATA and the blogger editor will not parse the script code and thus won't give any errors.

The reason why Facebook script gives errors in blogger is due to the presence of a special character (&) that is used before the variable "version" as highlighted in the code above. "&" will generate an error because the XML parser interprets it as the start of a character entity and thus it prompts an error that says:
The reference to entity "version" must end with the ';' delimiter.
2. Escape HTML entities

Another simple method is to escape all 5 special characters and instead use the legal characters as alternatives to the above 5.

Replace < with &lt;
Replace  > with &gt;
Replace  "  with &quot;
Replace  '  with &#039;
Replace  & with &amp;
PS: Note how every alternative character set ends with a delimiter (;)

This method will help you encode your AdSense code and paste it inside your template without errors. It will also help you paste HTML code inside blogger comments!

This method is also called HTML encoding and we have built a special tool for this purpose to help you encode HTML characters with ease.

Try this tool: Escape HTML Entities

Post a Comment

Thanks For Commenting We always appreciate your opnions.

Previous Post Next Post