2LeggedSpider

Displaying RSS feeds in ASP.NET

Posted in ASP.NET by Sumit Thomas on February 22, 2006

[tweetmeme style=”compact”]The XML control is one of the least used controls in ASP.NET. To be honest I haven’t used it much myself. I combined my little knowledge in XSL with the XML control to create a simple RSS reader. Here is the code for the WebForm

.rssContainer
{
border: 1px dotted #000000;
padding: 3px;
font-family: Arial, Verdana, Geneva;
font-size: 11px;
width: 100%;
}
#header
{
background-color: #f7f7f7;
border: 1px solid #000000;
}
#header h2
{
color: #333333;
}
#header .description
{
font-size: 14px;
font-weight: bold;
}



void Page_Load(object source, System.EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("https://2leggedspider.wordpress.com/feed/");
rssFeed.Document = xmlDoc;
rssFeed.TransformSource = rss.xsl;
}




    
    
    



The code as you can see is very simple. We create a XmlDocument object and open the feed using it. Then we pass the document to the XML control. You would also notice that we are passing an XSL source to the XML control through it’s TransformSource property. The XSL does all the formatting of the feed data. Lets look at the XSL code now.








<table class="rssContainer">
<tr>
<td>
<h2>
<a href="{link}" target="_blank">
</a>
</h2>
<div class="description">
</div>
</td>
</tr>
<tr>
<td>

</td>
</tr>
</table>


<a href="{link}" target="_blank"></a>  - 
  

<br /><i>
</i>
<hr />




The XSL code is pretty simple as you can see. Well I definetely will consider this option when I need to display any kind of XML content again.

Technorati: , ,
Tagged with: ,