|
||||||
Easy RSS in VB.NETI implemented an RSS feed for FTPOnline last night; .NET's XML serialization capabilities made it relatively painless. First, I created this class to model the feed. (I actually cheated and used .NET's xsd.exe utility, first to create a schema based on my own RSS feed, then to generate a VB.NET class from that schema. All I had to do then was tweak the code to use a collection instead of an array for the items.) Now all it takes to update the feed is to populate the RSS object and serialize it to XML:
Dim rssFeed As New rss()
Const BaseURL As String = "http://www.ftponline.com" With rssFeed.channel .title = "FTPOnline" .description = "Technical information for " & _ "developers and IT professionals from " & _ "the FTP family of publications and conferences." .link = BaseURL End With ' -- Query database for recent items ' Loop through DataReader, adding items to feed Do While drFeatures.Read Dim rssItem As New rssChannelItem() With rssItem .link = CStr(drFeatures!headerLink) ' Fully-qualify relative links If InStr(.link, "http://") = 0 Then .link = BaseURL & .link End If .title = CStr(drFeatures!headerText) .description = CStr(drFeatures!text) .pubDate = Format(drFeatures!dateCreated, "R") End With rssFeed.channel.item.Add(rssItem) Loop drFeatures.Close() ' Serialize RSS object to file Dim xml As New XmlSerializer(GetType(rss)) Dim strFile As New FileStream("d:\path\rss.xml", FileMode.Create) ' Empty namespaces collection eliminates ' default namespace attributes from XML root Dim xmlns As New XmlSerializerNamespaces() xmlns.Add(String.Empty, String.Empty)  xml.Serialize(strFile, rssFeed, xmlns) Comments
Post a comment
|
Articles
Easy RSS in VB.NETIs Inheritance Overrated? A Tale of Tabbed Pages Categories
.NETBlog Career Cycling Geek Humor Microsoft Music Personal Rants Reading Software Tech Usability VB Archives
March 2008December 2006 August 2006 April 2006 February 2006 January 2006 December 2005 September 2005 June 2005 May 2005 March 2005 January 2005 December 2004 September 2004 July 2004 June 2004 January 2004 August 2003 July 2003 May 2003 April 2003 March 2003 February 2003 January 2003 December 2002 November 2002 Misc
Talk to MeSubscribe |
|||||
Thanks Phil! Just what I was looking for!
Even easier:
DataSet ds = new DataSet();
ds.ReadXml("http://www.startupskills.com//index.xml",XmlReadMode.Auto);
'Put it in a datagrid
DataGrid1.DataSource=ds.Tables[2];
DataGrid1.DataBind();
This is the quickest and dirtiest way I know to get an RSS link, for example, for the latest article.
-Rich
http://www.startupskills.com