Quick Question: Best method to store this program data (RSS FEED ITEMs)

hyperspace

New member
Joined
Jul 9, 2011
Messages
2
Programming Experience
1-3
Hello,

I am making an RSS Application which works so far; it obtains feeds and stores them into a list of type RSS ITEM which is a structure with common RSS ITEM properties etc. I am just asking simply, what is the best way to save the data for later retrieval ? I can't use comma or colon delimited file, I could try a tab spaced text file but that might cause problems too. Could anyone recommend a suitable alternative, is there a database built into windows that I could save the data? I would rather not use Access to do this..
 

hyperspace

New member
Joined
Jul 9, 2011
Messages
2
Programming Experience
1-3
Working RSS feed reader

I decided to serialize it... Here is a working RSS feed reader... if anyone wants to use it feel free.

VB.NET:
' For the stringbuilder
Imports System.Text
' For the feeds
Imports System.Xml
' For the serialization of the feed items
Imports System.Runtime.Serialization


Public Class clsRss
    ' Store a list of rss feeds
    Private rssFeeds As List(Of rssFeed) = New List(Of rssFeed)
    ' Store a list of rss feed items
    Private rssItems As List(Of rssItem) = New List(Of rssItem)
    ' For the feed object
    Private tmpFeed As rssFeed
    ' Save the rss feed subscriptions to file
    Private strFeedFile As String = "feeds.ct"
    ' For the feed item
    Private tmpFeedItem As rssItem
    ' Save the rss feed items to file
    Private strItemfile As String = "items.ct"
    ' Save the object from file to be loaded later
    Private serList As New Formatters.Binary.BinaryFormatter

    Sub New()

    End Sub

    Public Function FeedFileExists()
        If (IO.File.Exists(strFeedFile)) Then Return True Else Return False
    End Function

    Public Function ItemFileExists()
        If (IO.File.Exists(strItemfile)) Then Return True Else Return False
    End Function

    Public Sub NewFeedSubscription()
        tmpFeed = New rssFeed
        tmpFeed.Name = diaAddRss.txtRssTitle.Text
        tmpFeed.Link = diaAddRss.txtRssLink.Text
        tmpFeed.Status = "y"
        If (rssFeeds.Contains(tmpFeed)) Then
            MsgBox("This feed already exists")
        Else
            rssFeeds.Add(tmpFeed)
        End If

        IO.File.Delete(strFeedFile)

        Using saveFile As IO.FileStream = IO.File.OpenWrite(strFeedFile)
            serList.Serialize(saveFile, rssFeeds)
            saveFile.Close()
        End Using

        PopulateFeedSubscriptionsList()

    End Sub

    Public Sub PopulateFeedSubscriptionsList()
        tmpFeed = New rssFeed

        Using saveFile As IO.FileStream = IO.File.OpenRead(strFeedFile)
            rssFeeds = CType(serList.Deserialize(saveFile), List(Of rssFeed))
            saveFile.Close()
        End Using

        frmMain.lstRss.Items.Clear()

        For Each tmpFeed As rssFeed In rssFeeds
            If (tmpFeed.Status = "y") Then
                frmMain.lstRss.Items.Add(tmpFeed.Name, True)
            Else
                frmMain.lstRss.Items.Add(tmpFeed.Name, False)
            End If
        Next
    End Sub

    Public Sub FetchFeedData()
        tmpFeed = rssFeeds(frmMain.lstRss.SelectedIndex)
        tmpFeedItem = New rssItem
        Dim feedReader As New Xml.XmlTextReader(tmpFeed.Link.ToString)

        While feedReader.Read
            tmpFeedItem = New rssItem
            If (feedReader.Name = "item") Then
                While (Not ((feedReader.Name = "item") And _
                            (feedReader.NodeType = Xml.XmlNodeType.EndElement)) And _
                             feedReader.Read())
                    If (feedReader.NodeType = Xml.XmlNodeType.Element) Then
                        Select Case (feedReader.Name.ToLower())
                            Case "title"
                                tmpFeedItem.Name = feedReader.ReadString()
                            Case "link"
                                tmpFeedItem.Link = feedReader.ReadString()
                            Case "desc"
                                tmpFeedItem.Desc = feedReader.ReadString()
                        End Select
                    End If
                End While
            End If
            If (Not rssItems.Contains(tmpFeedItem)) Then
                If (Len(tmpFeedItem.Name) > 0 And Len(tmpFeedItem.Link) > 0) Then
                    rssItems.Add(tmpFeedItem)
                End If
            End If
        End While

        Using saveFile As IO.FileStream = IO.File.OpenWrite(strItemfile)
            serList.Serialize(saveFile, rssItems)
            saveFile.Close()
        End Using

        UpdateItemBox()
    End Sub

    Public Sub UpdateItemBox()
        tmpFeedItem = New rssItem

        Using saveFile As IO.FileStream = IO.File.OpenRead(strItemfile)
            rssItems = CType(serList.Deserialize(saveFile), List(Of rssItem))
            saveFile.Close()
        End Using

        frmMain.lstItems.Items.Clear()

        For Each tmpFeedItem As rssItem In rssItems
            frmMain.lstItems.Items.Add(tmpFeedItem.Name)
        Next
    End Sub

    <Serializable()>
    Private Structure rssFeed
        ' Name - Link
        Dim strName As String
        Dim strLink As String
        Dim strStatus As String

        Property Link
            Get
                Link = strLink
            End Get
            Set(ByVal value)
                strLink = value
            End Set
        End Property

        Property Name
            Get
                Name = strName
            End Get
            Set(ByVal value)
                strName = value
            End Set
        End Property

        Property Status
            Get
                Status = strStatus
            End Get
            Set(ByVal value)
                strStatus = value
            End Set
        End Property
    End Structure

    <Serializable()>
    Public Structure rssItem
        Dim strName As String
        Dim strLink As String
        Dim strDescription As String

        Property Name
            Get
                Name = strName
            End Get
            Set(ByVal value)
                strName = value
            End Set
        End Property

        Property Link
            Get
                Link = strLink
            End Get
            Set(ByVal value)
                strLink = value
            End Set
        End Property

        Property Desc
            Get
                Desc = strDescription
            End Get
            Set(ByVal value)
                strDescription = value
            End Set
        End Property

    End Structure
End Class
 
Top Bottom