Purpose
The purpose of this project is to demonstrate how to create a simple RSS feed reader using an ASPX page.
NOTE: If you are reading from something other than the stream (shown) you may need to try the following to resolve "Illegal Characters In Path" errors:
rssDoc.Load(new StringReader(rssFeed))
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim rssStream As Stream
Dim myRequest As WebRequest = WebRequest.Create("http://www.somesite.com/apage.php?feed=1234")
myRequest.Method = "GET"
myRequest.ContentType = "text/xml"
Try
Dim myResponse As WebResponse = myRequest.GetResponse()
rssStream = myResponse.GetResponseStream()
Dim rssDoc As New XmlDocument()
rssDoc.Load(rssStream)
Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
Dim title As String, link As String, description As String
For X As Integer = 0 TO rssItems.Count - 1
Try
title = rssItems.Item(X).SelectSingleNode("title").InnerText
Catch ex As Exception
title = ""
End Try
Try
link = rssItems.Item(X).SelectSingleNode("link").InnerText
Catch ex As Exception
link = ""
End Try
Try
description = rssItems.Item(X).SelectSingleNode("description").InnerText
Catch ex As Exception
description = ""
End Try
Response.Write ("Title = " & title & "<br />Link = " & link & "<br />Description = " & description & "<br />")
Next
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
</script>