Skip to main content

Using CDATA Section to Escape Characters on Blogger.com

XDATA

We can preserve our string using CDATA section:


CDATA Section

Blogger uses XHTML. It is an application of XML which extends the functionality of HTML so that it can operate with the custom data provided from the server.

Such as the <b:widget>, <data:post.title/>, <b:loop>, <b:if> and other Blogger data tags.

The string within the <![CDATA[ ]]> (Character Data) section will be interpreted as only character data, not markup. This is the definition.


The Forbidden Characters

  • < (less than character)
  • > (greater than character)
  • & (and character)

The double quotes (") and single quote (') in Blogger template will be automatically replaced by &quot; and &#39;, respectively.


Usage in Script Tag

The script tag (JavaScript) can be placed anywhere in the head or in the body section of a Blogger blog, depends on what's the purpose of that particular application.

The CDATA section can be declared like so:

This will be useful if we put the script in the template section or in the post itself, and that script has forbidden characters.

Example:

The CDATA opening and closing marks are declared as comments in the script.

I've tried declaring them as comments and not, and both actually work.

That example above is the common method I observed in the Blogger templates.

This method will also work if we paste, for instance, jQuery or other JavaScript library onto the template.

Accessing Blogger Data as JavaScript Variable

If we need to get the value from a particular Blogger <data>, this is how we do it:


Usage in Styling (CSS)

Blogger provides us with <b:skin> tag (in the HTML template). We can put our CSS inside that.

The CDATA section can be declared like so:

Example:

But, if we do not want to put the styling inside the <b:skin>, and that code has forbidden characters, then do this:

The CDATA section marks are also declared as comments in the CSS.

Example:


Other

Here's a list of other escaped characters:

  • < (less than character) is &lt;
  • > (greater than character) is &gt;
  • & (and character) is &amp;
  • " (double quotes character) is &quot;
  • ' (single quote character) is &apos; or &#39; in decimal

This is a post about using it (the escaped character) to solve that kinda error notification from Blogger.


Port Raptor also made that encoder/decoder tool at this link.

CML
Last modified on

Comments

  1. In 2019, i found this valuable gems, i should keep this right now, many thanks for great explanation.

    ReplyDelete

Post a Comment

Monkey Raptor uses cookies or biscuits 🍪 for analytics, functionality, and advertisements. More info in Privacy Policy