Parse HTML for Adsense Code and Blogger Posting

| Feb 17, 2009

Convert HTML for Adsense Code


This article will inform you how to make the code compatable in XML Blogger Template. To use AdSense code inside a post it is necessary to "escape" the AdSense code. The reason: If you put the code into your template just as it is written when you display the source code for the page, the Google data is invisible...that does not make Google happy and it is a TOS violation of AdSense...and they will pull your account for that!

Adsense does not allow you to alter their code other than "minor" edits. what we are going to do is considered a "minor" edit.

I contacted AdSense with the following question:

Subject: Wrapping Adsense code in blog post Date: Wed, 18 Apr 2007 09:12:15 -0700
"I would like to put the adsense ads inside of a blog post. To make it look EXACTLY like you give it to me (when viewed as a Page source code) it is necessary for a minor alteration. For Blogger to parse the Adsense Code in XML template, the Javascript has to be escaped, using html entities...It looks EXACTLY like you gave it out when viewed by Page source, so is this permissable?"


Adsense answered my email with this:

"Hi Bonnie,
We do permit minor edits to the AdSense code to place inside the blog posts. Please keep in mind publisher may not alter any portion of the code or manually change the layout of the ads. For instance, publishers may not alter the ad height variable to mask the Ads by Google moniker.
Thanks for your cooperation."

Sincerely,
Sean
The Google AdSense Team


So here is how we are going to parse the HTML to make it compatable and when viewed by using the Page Source code, it will look exactly as given to you by Adsense.

This is an example of a piece of Adsense code as given out by Adsense:



You are going to change the (<) to (<) and the (>) to (>) and the quote marks ( " ) to (") They will all be HTML entities. The code will then look like this:




Parse HTML Tool
taken from blogcrowds.com

Have you ever tried to insert the Google Adsense code directly into your Blogger XML Template and get this error?

"Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly. XML error message: The processing instruction target matching "[xX][mM][lL]" is not allowed."

So, you resolve to insert the Adsense code using blogger widgets. However that means your widgets can not appear within each post, the best spots to place your ads. Don't worry, there is a way of inserting Adsense code straight into your XML templates.

Since Blogger started using XML everything is more strict and standardized. The above error simply mean the Adsense code is not standized XML and solve it we need to replace all the html character such as '<' with '>' '"' with '"'. For example:

<script type="text/javascript"><!--
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";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


would be:



You can use a web-tool at www.blogcrowds.com for parsing the Google Adsense code or others.
This tool also can be used for inserting HTML code to your posting in Blogger.com

Please keep in mind that this tool should only be used to add Google Adsense into your Blogger XML Template, any other edit made to Adsense is prohibited and we will not be responsible for the consequences.

Minor edits on Google Adsense Code for Blogger Beta/XML are allowed as long as the resulting Adsense Code generated by Blogger is exactly the same as given from Google Adsense Code Generator.

Where you can place the parsed HTML code?

Here are some tips for where in the XML Blogger Template you should paste the parsed HTML code.

Powered by