Use CDATA in RSS Feed to add HTML and links

If you want to dress your rss feed there are two ways.

First you can use CDATA tag and second one is that you can include style sheet in your “.xml” file.

I am giving here a brief example. By observing the code hope you can understand details.

CDATA is very powerful, if you use CDATA tag within the description tag, all the XML elements in the xml file of the RSS feed will be parsed except the one that is included in the CDATA section.

HTML code within CDATA will remain same.

Put the CDATA code within the

   
<description>  .... </description>

tags.

Typical code for CDATA is given below:

The starting code is:

<![CDATA[
and the ending code is:

]]>

================================= rss.xml ====================================

<?xml version="1.0" encoding="ISO-8859-1" ?> 

<?xml-stylesheet type="text/css"  href="http://www.YourWebSite.com/feed/rss.css" ?>

<channel>  

    <title>Your Home Page Title</title>  

    <link>http://www.YourWebSite.com</link>  

     <description> 

        <![CDATA[    

          Know bla bla bla of 

          <a href="http://www.YourWebSite.com">[ Read more...]</a>         

        ]]> 

        </description>
 </channel>

</rss>

=====================================================================

In the above example line

<?xml-stylesheet type="text/css"  href="http://www.YourWebSite.com/feed/rss.css" ?> 

is used to define the style. The typical example of a rss.css file is:
======================== rss.css =============================================

rss {display: block;font-family: verdana, arial;} description  { font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;color:orange;text-align:centre;font-size:1.2em;margin:0.3em; } title { display: block;margin: 5px;padding: 2px;color: gray;border-bottom: 1px solid silver; } link { display: block;font-size: small;padding-left: 10px; } item { display: block;padding: 2px 30px 2px 30px; } docs { display: block;background-color: #ffffe6;margin: 20px;text-align: center;padding: 5px;color: #7f7f7f;border: 1px solid silver; } lastBuildDate, guid, language, ttl, category, pubDate {display: none;}

=====================================================================

 

Leave a comment

Design a site like this with WordPress.com
Get started