--> 2 ways To Fix XML Parsing Errors in Blogger | Experience Lab - Online business creation and development guide for bloggers and startups

2 ways To Fix XML Parsing Errors in Blogger

Most often when you insert a Facebook JavaScript or AdSense JavaScript in your blogger template editor, you often come across XML Parsing er...

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! =)

COMMENTS

Name

Affiliate Marketing,12,Announcement,34,Bing,9,Bitcoin,38,blog,7,Blogger Resources,42,Blogger Templates,4,blogger tricks,156,Blogging ethics,70,Blogging tips,198,Bugs and Errors,34,Business,9,Copyright Violation,9,CSS and HTMLTricks,95,Designs,8,drop down menu,7,eBook,12,Email Marketing,7,Events,30,Facebook,30,Facebook tricks,49,Google,157,Google AdSense,42,Google Analytics,7,Google Plus,51,Google Plus Tricks,38,Guest Posts,112,home,2,How To,77,Internet,1,JSON Feeds,25,Kitchen Recipes,2,Label Based Sitemap Themes,1,Make Money Online,108,Marketing,16,MBT Blogger Templates,7,Menus,1,News,146,Pages,1,Posts,10,presentations,15,Responsive,10,Reviews,7,SEO,307,Settings,6,Shortcode,15,Sitemap Themes,1,Social Media,155,Technology,7,Templates,1,Tips,2,Tools,1,Traffic Tips,80,Video,19,Web Designing,62,web hosting,18,Webmaster Tools,97,Widgets,199,wordpress,26,
ltr
item
Experience Lab - Online business creation and development guide for bloggers and startups: 2 ways To Fix XML Parsing Errors in Blogger
2 ways To Fix XML Parsing Errors in Blogger
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO_kREzvNGvTOlbvGEGr9xbRk5RqASXQoWHhbQ5akcwsv_bepBjx8xQvQjKR8RJLm6ATiFhN-U_46KGiyYDlWVRdwR_55PrZ5Hi232TwpwmFAX00kyEqE2anET-3X0eKlb7QdGIwmllsI/?imgmax=800
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO_kREzvNGvTOlbvGEGr9xbRk5RqASXQoWHhbQ5akcwsv_bepBjx8xQvQjKR8RJLm6ATiFhN-U_46KGiyYDlWVRdwR_55PrZ5Hi232TwpwmFAX00kyEqE2anET-3X0eKlb7QdGIwmllsI/s72-c/?imgmax=800
Experience Lab - Online business creation and development guide for bloggers and startups
https://www.experiencelab.info/2015/08/2-ways-to-fix-xml-parsing-errors-in.html
https://www.experiencelab.info/
https://www.experiencelab.info/
https://www.experiencelab.info/2015/08/2-ways-to-fix-xml-parsing-errors-in.html
true
2959477579779989044
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy