BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Monday, March 13, 2006
Syndicate Me

RSS has quickly picked up as an effective way of monitoring updated content on web sites (I even have one for this site). There are many applications available to aggregate these feeds. RSS is common enough that RSS aggregation is available (or soon to be) in popular web browsers. What if you wanted your own application or web site to include RSS feed information?

Aggregating and parsing RSS feed information via System.XML namespace of .NET is a lot easier than it sounds. Fortunately RSS is a standard structure XML file. The sub-elements of each item element contain the update information. I have created three (extremely basic) separate examples (BDS 2006, VB.NET 2005 and ASP.NET) of including feed information in your application. (I also put some together using the MSXML ActiveX library that I’ll probably put in another post)

Setting the sample (WinForm) application up in BDS 2006 (Delphi®) and VB.NET 2005 is pretty much the same. On a form I place a Button, TextBox and RichTextBox (screenshot is the two side-by-side).

The TextBox is where one enters the URL of a RSS feed. When the button is clicked the RichTextBox is filled with the feed sub-element information. They both need to use the System.XML namespace.

VB.NET Code
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim XMLDoc As New System.Xml.XmlDocument
Dim rssItems As System.Xml.XmlNodeList
Dim child, cn As System.Xml.XmlNode

RichTextBox1.Clear()
XMLDoc.Load(TextBox1.Text)
' each of the sub-elements of the item element contain the feed information
rssItems = XMLDoc.GetElementsByTagName("item")
For Each child In rssItems
For Each cn In child.ChildNodes
' you could filter and/or process each element by name - depending
' on what you'd like to do with node data (i.e. hyperlink to the
' actual post)

RichTextBox1.AppendText(cn.Name)
RichTextBox1.AppendText(vbCr)
RichTextBox1.AppendText(cn.InnerText.Trim)
RichTextBox1.AppendText(vbCrLf)
Next
Next
End Sub


Delphi® Code
procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
XMLDoc: System.Xml.XmlDocument;
rssItems: System.Xml.XmlNodeList;
child, cn: System.Xml.XmlNode;

begin
RichTextBox1.Clear;

XMLDoc:= XmlDocument.Create;
XMLDoc.Load(TextBox1.Text);
rssItems:= XMLDoc.GetElementsByTagName('item');
For child in rssItems do
begin
For
cn in child.ChildNodes do
begin
RichTextBox1.AppendText(cn.Name);
RichTextBox1.AppendText(#13);
RichTextBox1.AppendText(cn.InnerText.Trim);
RichTextBox1.AppendText(#13#10);
end;
end;
end;


To display the same information on an ASP.NET web page create a document with the following code:
<%@ Page Language="VB" Debug = true%>
<%@ Import namespace="System.Xml" %>

<html>
<head>
<title>BPSoftware.com - RSS Reader</title>
</head>

<body bgcolor="#f8f8ff">
<%

Dim XMLDoc As New System.Xml.XmlDocument
Dim rssItems As System.Xml.XmlNodeList
Dim child, cn As System.Xml.XmlNode

XMLDoc.Load("http://www.techweb.com/rss/all.xml ")
rssItems = XMLDoc.GetElementsByTagName("item")
For Each child In rssItems
For Each cn In child.ChildNodes %>
<%=cn.Name%>

<br />
<%=cn.InnerText.Trim%>
<br />
<%
Next
Next
%>


</body>
</html>

After you get the basic connectivity and processing working, it is easy to filter our and process only the sub-elements that you’d like to include in your application or on your web page. There is a lot that can be done with this inside of an application; I figured I’d go with the basics to help spark some interest. For some unknown reason I've abandoned C some time ago, but if anyone wants to follow up with the same in C please do....

Labels: , , ,

posted by Brad Prendergast at 6:08:00 AM
Comments:
Links to this post:

Create a Link

Recent Posts
 Around the network of silken thread
 I did not win
 Please Pick Me!
 CursorText
 A Few Good Shows
 MyOwnConversion
 Where in the world?
 Remember SWAG?
 Express
 Adieu George!

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger