Pages

Friday, December 7, 2012

2 Ways To Fix Blogger Javascript / XHTML "Error parsing XML" problem, for Banner AD Codes

Have you ever got following error message or similar when adding 3rd party Javascript codes (esp. banner AD coeds from  advertising company) into Blogger (Blogspot.com) template ?

Error parsing XML, line 1205, column 91: The reference to entity "u" must end with the ';' delimiter.

And if you paste the same Javascript codes into a HTML/Javascript widget, it will not be working but no error message at all.

It happens in most cases when you got the banner AD Javascript codes from an 3rd party advertising company.

Why it happens is because, the Blogger templates are based on XML, which is more strict than regular HTML. XML requires that you can not use 5 special characters directly in the HTML/JavaScript codes, you have to use their entities' name.

The fix is simple.

2 Ways to Fix the "Error parsing XML" problem in Blogger

You can fix the problem in 2 ways, either will be working.

First method, replace a few special characters in the JavaScript codes manually. If the codes are only in a few lines, then this is easier;

Second method, add the codes inside a CDATA section.

Here's the details.

Fix #1,  replace the special characters in your Javascript codes

Here's a chart of the special characters need to be replaced in your JavaScript codes:

Special codeReplace with entity name
>>
<&lt;
&&amp;
"&quot;

An explanation can be found from the Wikipedia reference here.

Example: You got a few lines of  JavaScript codes from an AD company to display their banner ADs, inside the codes there are a few  '&'.

Fix: Replace all the '&' with '&amp;'

Easy way:  Use following free tool to do the replacement automatically:

XML/JavaScript Special Characters' Escape (Encode) Tool

Fix #2, add the codes inside a CDATA section

In this fix, enclose your actual JavaScript codes between a pair of tags //<![CDATA[ and //]]>, like:

<script type="text/javascript">
//<![CDATA[
    put the JavaScript scripts here
//]]>
</script>

That means, you have to add the  pair of tags //<![CDATA[ and //]]> manually into your Javascript codes as showing in above, then paste all the codes into Blogger template or widget.


It’s Your Turn

Have you ever got the Javascript / XHTML "Error parsing XML" problem before? How did you fix the problem? Is this fix working for you? Share your experience and insights in the comments box below.


No comments

Post a Comment