Creating an RSS feed

1,766 views

Published on

Creating and displaying RSS feed by using LINQ asp.net
by
http://www.livetolearn.in

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,766
On SlideShare
0
From Embeds
0
Number of Embeds
210
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Creating an RSS feed

  1. 1. RSS Feed using ASP.NET & Linq http://www.livetolearn.in
  2. 2. <ul><li>RSS is a format for an XML document that describes a list of items, such as blog entries or news headlines. </li></ul><ul><li>The document may just be a stream of XML created on the fly rather than a static file. </li></ul>http://www.livetolearn.in
  3. 3. <ul><li><rss> </li></ul><ul><li><channel> </li></ul><ul><li><item> </li></ul><ul><li><title></title> </li></ul><ul><li><description></description> </li></ul><ul><li><link></link> </li></ul><ul><li><pubDate></pubDate> </li></ul><ul><li><!--..............................--> </li></ul><ul><li></item> </li></ul><ul><li></channel> </li></ul><ul><li></rss> </li></ul>http://www.livetolearn.in
  4. 4. <ul><li>Add a generic handler named rsshandler.ashx </li></ul><ul><li>Add import directive Imports System.Xml.Linq </li></ul><ul><li>Replace the process request() subroutine as follows </li></ul>http://www.livetolearn.in
  5. 5. <ul><li>Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest </li></ul><ul><li>Dim rssdoc As New XDocument(New XDeclaration( &quot;1.0&quot;, Nothing, Nothing)) </li></ul><ul><li>rssdoc.Add( New XComment( &quot;My RSS Feed uses XML to Linq datasource&quot;)) </li></ul><ul><li>Dim rssrootelement As New XElement( &quot;rss&quot;, New XAttribute( &quot;version&quot;, &quot;2.0&quot;)) </li></ul><ul><li>Dim rsschannel As New XElement( &quot;channel&quot;) </li></ul><ul><li>Dim rsstitle As New XElement( &quot;title&quot;, &quot;RK's News Channel&quot;) </li></ul><ul><li>rsschannel.Add(rsstitle) </li></ul><ul><li>Dim rssdesc As New XElement( &quot;description&quot;, &quot;Description of Channel&quot;) </li></ul><ul><li>rsschannel.Add(rssdesc) </li></ul><ul><li>Dim rsslink As New XElement( &quot;link&quot;, &quot;http://www.livetolearn.in/&quot;) </li></ul><ul><li>rsschannel.Add(rsslink) </li></ul><ul><li>Dim intCtr As Integer </li></ul><ul><li>Dim rssitem As XElement </li></ul>RSS Document Comment RSS Channel Title (Appears at title bar) RSS Title Link http://www.livetolearn.in
  6. 6. <ul><li>For intCtr = 0 To 10 </li></ul><ul><li>rssitem = New XElement( &quot;item&quot;, _ </li></ul><ul><li>New XElement( &quot;title&quot;, &quot;This is item number &quot; & intCtr.ToString), _ </li></ul><ul><li>New XElement( &quot;description&quot;, &quot;Description for item # &quot; & _ </li></ul><ul><li>intCtr.ToString), _ </li></ul><ul><li>New XElement( &quot;link&quot;, &quot;http://www.livetolearn.in/item&quot; & _ </li></ul><ul><li>intCtr.ToString & &quot;.aspx&quot;)) </li></ul><ul><li>rsschannel.Add(rssitem) </li></ul><ul><li>Next </li></ul><ul><li>rssrootelement.Add(rsschannel) </li></ul><ul><li>rssdoc.Add(rssrootelement) </li></ul><ul><li>rssdoc.Save(( New System.IO.StreamWriter _ </li></ul><ul><li>(context.Response.OutputStream))) </li></ul><ul><li>End Sub </li></ul>This for loop creates 10 sample items with Description. http://www.livetolearn.in
  7. 7. <ul><li>Now, browse the rsshandler.ashx with Internet Explorer 7 and above or Firefox </li></ul>http://www.livetolearn.in
  8. 8. Displaying XML data http://www.livetolearn.in
  9. 9. <ul><li>Add an XmlDataSource control to a ASP.NET page </li></ul><ul><li>Click smart tag </li></ul><ul><li>Choose configure data source </li></ul><ul><li>Enter the URL of the RSS feed </li></ul><ul><li>For example </li></ul><ul><li>http://www.livetolearn.in/blog/?feed=rss2 </li></ul><ul><li>Type the following in Xpath expression text box </li></ul><ul><li>Rss/channel/item </li></ul><ul><li>Add a data list control and set source to Xmldatasource1, </li></ul><ul><li>Edit Item template of data list control </li></ul><ul><li>Add a hyper link control inside the item template </li></ul><ul><li>Set it’s data binding property as follows Navigate URL – xPath(“link”) </li></ul><ul><li>xPath(“title”) </li></ul><ul><li>It displays the list of items from rss feed. </li></ul>http://www.livetolearn.in
  10. 10. <ul><li>By adding more items in Item Template (e.g. Text box), we can display description from RSS feed. </li></ul><ul><li>******** </li></ul>http://www.livetolearn.in

×