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.
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:- (<) - 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.
Two ways to fix XML errors 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:
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 &
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.
- Try this tool: Escape HTML Entities
- Or this tool: HTML to XML Parser
No comments:
Post a Comment