Guide to Parsing Your Adsense Code

Posted by redDevil | 2/19/2008 12:27:00 PM | , , | 0 comments »

                                                                Many a times you get the error message when you try to edit your blog’s html that “your template could not be parsed as it is not well formatted” or “Your template could not be parsed as it is not well-formed” and likewise. The problem here is you are trying to add the code of your ads which contain JavaScript elements directly into your blog’s xml code through the edit html interface.

The problem is caused by incorrect dynamic interpretation of Blogger XML template when it generates the HTML webpage for the blog page that is requested, probably due to the fact that the AdSense ad code or other code is not a valid XML, coupled with the fact that some ASCII characters have special meaning and reserved functions, confusing Blogger blogging engine.


It is possible to add the adsense/adbrite code for your ads into your blog’s xml template by parsing them.

The resolution to the JavaScript based coding does not work in Blogger HTML template error can be solved by replacing special characters or symbols in the script to HTML code. Check out the list below for which ASCII characters that need to be replaced with their corresponding HTML code. Using HTML code will ensure that Blogger render the character correctly when serving the page to the viewer.

< - &lt;

> - &gt;



ie:, replace the '<' symbol in your code with the '&lt;' symbol and '>' symbol with the '&gt;' symbol.

Above two is enough to make Google AdSense works in Blogger template. For other scripts, such as AdBrite ad code, you will need to replace more characters such as those listed below.

& = &amp;

” = &quot;



You can do this easily by placing your code into a word document and using word’s find and replace option, to replace the above ASCII characters.

For example, a Google AdSense code should become looks similar to code below:

&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-XXXXXXXXXXXXXXX";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = "336x280_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_text = "000000";
google_color_url = "000000";
//--&gt;&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;


You need not worry about breaking the adsense terms of service (TOS), about altering the ad code, because once published the code looks exactly similar to the code before it was parsed. Anyone viewing the source code of your blog would exactly see it as the code that adsense gave you.


Whenever you encounter the xml error message when adding a code to your blog’s xml template, you can try this method just to ensure you code is not having a xml parsing problem. Happy Blogging!

Drop A Comment Here

Don't Spam

0 comments:

RSS Feed