How to read RSS feed by using SyndicationFeed Class in VB.net?

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 596
Suppose we have a model as under

Public Class RSS
Public Property Id() As String
Get
Return m_Id
End Get
Set
m_Id = Value
End Set
End Property
Private m_Id As String
Public Property QuestionID() As String
Get
Return m_QuestionID
End Get
Set
m_QuestionID = Value
End Set
End Property
Private m_QuestionID As String
Public Property QuestionTitle() As String
Get
Return m_QuestionTitle
End Get
Set
m_QuestionTitle = Value
End Set
End Property
Private m_QuestionTitle As String
Public Property QuestionDescription() As String
Get
Return m_QuestionDescription
End Get
Set
m_QuestionDescription = Value
End Set
End Property
Private m_QuestionDescription As String
Public Property PublishDate() As DateTime
Get
Return m_PublishDate
End Get
Set
m_PublishDate = Value
End Set
End Property
Private m_PublishDate As DateTime
End Class


The below code will read RSS feed by using SyndicationFeed Class in VB.net

Imports System.Collections.Generic
Imports System.Linq
Imports System.ServiceModel.Syndication
Imports System.Xml

Namespace ConsoleApplication1
Public Class RSSReader
Public Function GetRSSFeeds() As IEnumerable(Of RSS)
Dim url As String = <RSS FEED URL>
Dim feed As SyndicationFeed = Nothing

Using reader = XmlReader.Create(url)
feed = SyndicationFeed.Load(reader)
Dim syndicationItems = feed.Items.ToArray()

For i As Integer = 0 To syndicationItems.Length - 1
yield Return New RSS() With { _
Key .QuestionID = syndicationItems(i).Id, _
Key .QuestionTitle = syndicationItems(i).Title.Text, _
Key .QuestionDescription = syndicationItems(i).Summary.Text, _
Key .PublishDate = syndicationItems(i).PublishDate.[Date] _
}
Next
End Using
End Function
End Class
End Namespace


As can be figure out that, we are using SyndicationFeed Class that represents a top-level feed object, <feed> in Atom 1.0 and <rss> in RSS 2.0. It resides under System.ServiceModel.Syndication namespace.We are using yield statement for maintaining a stateful iteration.

Comments or Responses

Login to post response