2 ways To Fix XML Parsing Errors in Blogger

fix XML errors in blogger editorMost often when you insert a Facebook JavaScript or AdSense JavaScript in your blogger template editor, you often come across XML Parsing errors that prompts and says "The reference to entity "version" must end with the ';' delimiter." Blogger blogs are coded in XHTML and  XML is quite strict in following correct syntax formatting than HTML. XML is surely unforgiving in this case. Blogger interprets all your document as XML rather than as HTML. 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 a 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.

error parsing xml in blogger

What are the special characters in XML that causes error?

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:

  1. (<)  - less than

  2. (&) - ampersand

  3. (>) - greater than

  4. (")  - double-quote

  5. (')  - 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.

Two ways to fix XML errors in Blogger

XML errors can be avoided by using two methods:

  1. Use CDATA
  2. 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 exists inside the CDATA and blogger editor will not parse the script code and thus wont 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 as HTML encoding and we have built a Special tool for this purpose to help you encode HTML characters with ease.

Need Help?

I hope now you will be able to add social media plugins and third party scripts inside your blogger templates without any errors. Do let me know if you need any further assistance or clarification on any point. Would love to give a hand buddies! =)

If you don't want to get yourself into Serious Technical Trouble while editing your Blog Template then just sit back and relax and let us do the Job for you at a fairly reasonable cost. Submit your order details by Clicking Here »

17 comments

PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with 'Links' will be deleted immediately upon our review.
  1. it's very simple but everyone should clearly know about this.

    ReplyDelete
    Replies
    1. Indeed understanding something is way more important then straight away applying it =)

      Delete
  2. Yeh Cheez!
    This is the tutorial that I was searching for, on Google. I found nothing useful. Thank's for sharing.

    ReplyDelete
  3. I simply use online tool to parsing html code :). Thans for indepth detail

    ReplyDelete
  4. Thanks. You have saved me alot.

    ReplyDelete

  5. thank you , have shared this Turial . I just find to fix my problem here . One more thing that I want to ask how to make a blog post automatically updated on the fans page ? For now rss graffiti is not working
    Thanks :)
    http://memberi-cara.blogspot.com

    ReplyDelete
  6. Thank you so much, I Have done this

    ReplyDelete
  7. wow it really worked on my blog. thank you bro. i have been having this issue since and its disallowed me from posting some useful scripts. but thanks alot it worked.

    ReplyDelete
  8. I have question and am just learning how this stuff works. Google changed everything over to "https://" from the old "http://" and now it throws in so many errors with the templates. I am using one of Bloggers Templetes that come with the normal signup process.

    When looking for reasons why I have +1800 errors on my week old blog, and trying to find ways to fix it is driving me crazy and I am no code person by any means. But can read and mess stuff up quickly. But this what the beginning of the Blogger Blog Template looks like:

    I have tried to change the "http://" over to "https://" add check to see if it would solve the problem. No it did not, as they both http and https went to error code 404 not found.

    How can one person fix the problem within the Template itself it Google Blogger puts out these Templates with the errors and expects us to fix it?

    Wow it is just Microsoft selling Windows 10 and then turning around and telling us that there is errors within the program. But for $xx.xx we can sell you the fix it and being running in no time.

    Or even a vehicle manufacture selling you a brand new vehicle with a motor that is known to blowup or lockup after 30,000 miles. And tell us that for $xx.xx we can have it replaced with a new one that does not have that problem.

    See what I mean...

    Anyways any suggestions on how to fix this problem as it is on every page since the https thing started pushing hard and now I have so many errors on my pages they are counting it against me for their errors.

    ReplyDelete
  9. Do you have any video of this Topic?

    ReplyDelete
  10. Still working until this 2016. I have just fixed this issue at my Blogger. Thanks so much.
    Very useful and simple to implement.

    ReplyDelete
  11. I have placed the square brackets code in template and it passed the code without error. But the Facebook Plugin is not showing up on my blogspot site instead it gives a link to the Page. I don't know where am I going wrong. Please help.

    ReplyDelete