Using XMLTextReader and DataSets to easily Data Mine Google News with very few lines of code.

by michael 7/10/2008 11:09:13 AM

Imports:
Imports System.Xml
Imports System.Data
 
Example Function:
Private Function ExtractGoogleNewsRSS(ByVal strSearchString As String) As Generic.List(Of NewsItem)
    Dim NewsItems As New List(Of NewsItem)
    Dim strSearchURL As String = String.Concat("http://news.google.com/news?hl=en&ned=us&q=", strSearchString, "&ie=UTF-8&output=rss")
    Using reader As XmlTextReader = New XmlTextReader(strSearchURL), _
          ds As New DataSet


        Dim dt As DataTable

        ds.ReadXml(reader)
        dt = ds.Tables(3)

        For Each row As DataRow In dt.Rows
            Dim itm As New NewsItem

            itm.Title = row("title")
            itm.PublishDate = row("pubdate")
            itm.Description = row("description")
            itm.URLString = row("link")

            NewsItems.Add(itm)
        Next
    End Using

    Return NewsItems
End Function

Private Class NewsItem
    Private _title As String
    Private _publishDate As Date
    Private _description As String
    Private _uRLString As String

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

    Public Property PublishDate() As Date
        Get
            Return _publishDate
        End Get
        Set(ByVal value As Date)
            _publishDate = value
        End Set
    End Property

    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

    Public Property URLString() As String
        Get
            Return _uRLString
        End Get
        Set(ByVal value As String)
            _uRLString = value
        End Set
    End Property
End Class

You can easily load the Google News RSS data into an "XmlTextReader".  The "ReadXml" method of the "DataSet" converts the xml data into a "DataSet".  The "NewsItem" class is just an example data container.

Currently rated 2.9 by 14 people

  • Currently 2.857143/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Michael Johnson Michael Johnson
Developer and Technologist.

E-mail me Send mail

Pages

    Recent comments

    Categories

    None


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2014

    Sign in