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 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.
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
"<" 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.
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 "" and ends with "]]>":
Next time when you add your Facebook code, enclose it inside CDATA as shown below:
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 < Replace > with > Replace " with " Replace ' with ' Replace & with &
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!
No comments:
Post a Comment