Thursday, April 17, 2008

Feed Reader/Rss Reader

Step.1:.....Path Of Rss
Private Sub ReadNews()
Dim rd As New FeedReader("http://news.google.co.in/news?hl=en&ned=in&q=surat&ie=UTF-8&as_drrb=q&as_qdr=w&as_mind=14&as_minm=11&as_maxd=21&as_maxm=11&output=rss")
'Dim rd As New FeedReader("http://www.easy-indian-food.com/Indian-cooking.xml")
'Dim rd As New FeedReader("http://content.msn.co.in/rsscache/healthfitness.rss")
DataList1.DataSource = rd.GetDataTable
DataList1.DataBind()
End Sub
--------------------------
Step.2:.....Class1
-------------------------
Imports Microsoft.VisualBasic

Public Class FeedReader
Private mvarTable As Data.DataTable
Private mvarObjColl As FeedCollection
Private mvarSourceFile As String

Sub New()
mvarObjColl = New FeedCollection
End Sub

Sub New(ByVal SourceFile As String)
Me.New()
ReadFile(SourceFile)
End Sub

Public Overloads Sub ReadFile(ByRef SourceFile As String)
mvarSourceFile = SourceFile
ReadFile()
End Sub

Public Overloads Sub ReadFile()
Dim _TmpDS As New Data.DataSet
'If System.IO.File.Exists(SourceFile) Then
_TmpDS.ReadXml(mvarSourceFile)
If Not (_TmpDS.Tables("item") Is Nothing) Then
mvarTable = _TmpDS.Tables("item")
End If
_TmpDS = Nothing
PopulateCollection()
'End If
End Sub

Private Sub PopulateCollection()
mvarObjColl.clear()
For Each _TmpRow As Data.DataRow In mvarTable.Rows
mvarObjColl.Add(New Feed(_TmpRow("title").ToString(), _TmpRow("link").ToString(), _TmpRow("pubDate").ToString, _TmpRow("description").ToString()))
Next
End Sub

Public Function GetDataTable() As Data.DataTable
Return mvarTable
End Function

Public ReadOnly Property Items() As FeedCollection
Get
Return mvarObjColl
End Get
End Property

Public Property SourceFile() As String
Get
Return mvarSourceFile
End Get
Set(ByVal value As String)
mvarSourceFile = value
End Set
End Property
End Class
---------------------------
Step.3: class2
---------------------------
Imports Microsoft.VisualBasic

Public Class FeedCollection
Private mvarObjCollection As Collection

Public Sub New()
mvarObjCollection = New Collection
End Sub

Public Overloads Sub Add(ByRef Value As Feed)
mvarObjCollection.Add(Value)
End Sub

Public ReadOnly Property Count() As Integer
Get
Return mvarObjCollection.Count
End Get
End Property

Public Sub Remove(ByVal IndexNo As Integer)
mvarObjCollection.Remove(IndexNo)
End Sub

Public ReadOnly Property Item(ByVal IndexNo As Integer) As Feed
Get
Return CType(mvarObjCollection(IndexNo), Feed)
End Get
End Property

Public Sub Clear()
mvarObjCollection.Clear()
End Sub
End Class
---------------------------------
step:3:Class 3
---------------------------------
Imports Microsoft.VisualBasic

Public Class Feed
Private mvarTitle As String
Private mvarLinkURL As String
Private mvarTime As String
Private mvarContent As String

Sub New(ByVal valTitle As String, ByVal valLinkURL As String, ByVal valPublishTime As String, ByVal valContent As String)
mvarTitle = valTitle
mvarLinkURL = valLinkURL
mvarTime = valPublishTime
mvarContent = valContent
End Sub

Public Property Title() As String
Get
Return mvarTitle
End Get
Set(ByVal value As String)
mvarTitle = value
End Set
End Property

Public Property LinkURL() As String
Get
Return mvarlinkURL
End Get
Set(ByVal value As String)
mvarlinkURL = value
End Set
End Property

Public Property PublishTime() As String
Get
Return mvarTime
End Get
Set(ByVal value As String)
mvarTime = value
End Set
End Property
Public Property Content() As String
Get
Return mvarContent
End Get
Set(ByVal value As String)
mvarContent = value
End Set
End Property
End Class

No comments: