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