|
Imports System.Xml
Imports System.Xml.XPath
Public Class RssChannel
Private mTitle As String
Private mDescription As String
Private mLink As String
Private mItems As New RssItemCollection
Public Property Items() As RssItemCollection
Get
Return mItems
End Get
Set(ByVal Value As RssItemCollection)
mItems = Value
End Set
End Property
Public Property Title() As String
Get
Return mTitle
End Get
Set(ByVal Value As String)
mTitle = Value
End Set
End Property
Public Property Description() As String
Get
Return mDescription
End Get
Set(ByVal Value As String)
mDescription = Value
End Set
End Property
Public Property Link() As String
Get
Return mLink
End Get
Set(ByVal Value As String)
mLink = Value
End Set
End Property
Public Shared Function GetRssChannel(ByVal Url As String) As RssChannel
Dim Rc As New RssChannel
Dim Xd As XPathDocument
Try
Xd = New XPathDocument(Url) 'adresteki xml belgesini okuyor, ve bir belge gıbı goruyor
Catch ex As Exception
MsgBox(ex.Message) 'okuma sırasında bir hata verırse
End Try
Dim Xp As XPathNavigator = Xd.CreateNavigator 'ayırac oluşturuyor
Dim Ni As XPathNodeIterator 'bir ayaırac oluşturuyor verılen sorguya gore belge uzerınde ayırma ıslemını gerçeklesştiriyor
'title
Ni = Xp.Select("/rss/channel/title")
Ni.MoveNext()
Rc.Title = Ni.Current.Value
Ni = Xp.Select("/rss/channel/description")
Ni.MoveNext()
Rc.Description = Ni.Current.Value
Ni = Xp.Select("/rss/channel/link")
Ni.MoveNext()
Rc.Link = Ni.Current.Value
Ni = Xp.Select("/rss/channel/item")
While Ni.MoveNext
Dim Ri As New RssItem 'yeni bir haber oluşturuyor
Dim Ni2 As XPathNodeIterator
Ni2 = Ni.Current.Select("link") 'item>Link
Ni2.MoveNext()
Ri.Link = Ni2.Current.Value
Ni2 = Ni.Current.Select("description") 'item>description
Ni2.MoveNext()
Ri.Description = Ni2.Current.Value
Ni2 = Ni.Current.Select("title") 'item>title
Ni2.MoveNext()
Ri.Title = Ni2.Current.Value
Rc.Items.Add(Ri) ' haberi ekliyor Channel'a
End While
Return Rc
End Function
End Class
|