Monday, November 30, 2009

Overview

What is RSS?
“RSS is a format for syndicating news and the content of news-like sites, including major news sites like Wired, news-oriented community sites like Slashdot, and personal weblogs. But it's not just for news. Pretty much anything that can be broken down into discrete items can be syndicated via RSS: the "recent changes" page of a wiki, a changelog of CVS checkins, even the revision history of a book. Once information about each item is in RSS format, an RSS-aware program can check the feed for changes and react to the changes in an appropriate way.” - Mark Pilgrim (read more)

What is RSS.NET?
RSS.NET is an open-source .NET class library for RSS feeds. It provides a reusable object model for parsing and writing RSS feeds. It is fully compatible with RSS versions 0.90, 0.91, 0.92, and 2.0.1, implementing all constructs.

Who can use RSS.NET?
Commercial, internal, open-source and all other developers can use RSS.NET. End users can not use RSS.NET directly. (read more)

When can I expect a binary release?
Once major milestones are completed and well tested. In other words, when it's ready. In the meantime, the code can compiled from the CVS and nightly TAR.

Reading

To read an RSS feed, use the following syntax:

C#:
string url = "http://sourceforge.net/export/rss2_sfnews.php?feed";
RssFeed feed = RssFeed.Read(url);

VB.NET:
Dim url As String = "http://sourceforge.net/export/rss2_sfnews.php?feed"
Dim feed As RssFeed = RssFeed.Read(url)

Creates a new instance of the RssFeed class with the contents of the SourceForge RSS feed.
To bind a ListBox to the items of a channel:

C#:
RssChannel channel = (RssChannel)feed.Channels[0];
listBox.DataSource = channel.Items;

VB.NET:
Dim channel As RssChannel = feed.Channels(0)
listBox.DataSource = channel.Items

Sets a listBox's datasource property to the downloaded feed's first channel's item collection.
To display the item's description in a Label:

C#:
private void listBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
    RssItem item = (RssItem)listBox.SelectedItem;
    label.Text = item.Description;
}

VB.NET:
Private Sub listBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
                                         Handles ListBox.SelectedIndexChanged
    Dim item As RssItem = listBox.SelectedItem
    label.Text = item.Description
End Sub

Sets a label's text property to the listBox's selected item's description on the listBox's SelectedIndexChanged event.
Writing

C#:
oleDbDataAdapter.Fill(exampleData);

VB.NET:
OleDbDataAdapter.Fill(exampleData)

The oleDbDataAdapter uses a oleDbConnection to a JET database to fill a typed dataset.
For each row in the table, add an item to the channel:

C#:
RssChannel channel = new RssChannel();
foreach(ExampleData.NewsRow row in exampleData.News.Rows)
{
    RssItem item = new RssItem();
     
    item.Title = row.news_title;
    item.Description = row.news_description;
    item.PubDate = row.news_date.ToUniversalTime();
     
    channel.Items.Add(item);
}

VB.NET:
Dim row As ExampleData.NewsRow
Dim channel As New RssChannel
For Each row In exampleData.News.Rows
   Dim item As New RssItem

   item.Title = row.news_title
   item.Description = row.news_description
   item.PubDate = row.news_date.ToUniversalTime

   channel.Items.Add(item)
Next

For each row, a new RssItem is created, filled with data, and added to the item collection.
Set the channel properties:

C#:
channel.Title = "My channel's title";
channel.Description = "My channel's description";
channel.LastBuildDate = channel.Items.LatestPubDate;

VB.NET:
channel.Title = "My channel's title"
channel.Description = "My channel's description"
channel.LastBuildDate = channel.Items.LatestPubDate

Sets the channel's lastBuildDate the the most current item's pubDate.
Finally, create and output the feed:

C#:
RssFeed feed = new RssFeed();
feed.Channels.Add(channel);
Response.ContentType = "text/xml";
feed.Write(Response.OutputStream);
Response.End();

VB.NET:
Dim feed As New RssFeed
feed.Channels.Add(channel)
Response.ContentType = "text/xml"
feed.Write(Response.OutputStream)
Response.End()

1 comment:

  1. Casino Finder (JtmHub) - Get directions, reviews and more
    Find 시흥 출장샵 Casino Finder 부산광역 출장안마 (JtmHub) with public transportation. 성남 출장안마 Find addresses, see photos and maps 포항 출장샵 of popular casinos in New 오산 출장마사지 Jersey.

    ReplyDelete