Parse RSS XML Feed in ASP

' exact URL of the RSS XML file you are wanting to parse

Dim objHTTP 'call object remotely
Dim RSSURL,RSSFeed 'set variables for RSS feed
Dim xmlRSSFeed 'set XML data into DOM object
Dim objItems,objItem, objChild 'temp variables to get various information
Dim title,description,link, pubdate 'variables that you are getting
Dim display 'This is the output variable

'convert raw XML to workable data
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP") "GET",RSSURL,false
RSSFeed = objHTTP.responseText

'load raw XML data into an object
Set xmlRSSFeed = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlRSSFeed.async = false

'clear objHTTP: No longer needed
Set objHTTP = Nothing

'This is where you get the information you are wanting
'When writing, I was using the following XML source:
' this code grabs all the "items" in the RSS Feed
Set objItems = xmlRSSFeed.getElementsByTagName("item")

'clear xmlRSSFeed: No longer needed
Set xmlRSSFeed = Nothing

' loop over all the items in the RSS Feed
For x = 0 to objItems.length - 1
' this code places the content from the various RSS nodes into local variables
Set objItem = objItems.item(x)
For Each objChild in objItem.childNodes
Select Case LCase(objChild.nodeName)
Case "title"
title = objChild.text
Case "link"
link = objChild.text
Case "description"
description = objChild.text
Case "pubdate" 'Note: pubDate in XML: Needs to be lowercase to work
pubDate = objChild.text
End Select
'This is where the display for each occurence is constructed
display = display & "<a href=""" & link & """>" & title & "</a><br />" & pubDate & "<br />" & description & "<br /><br />"



You must be logged in to post a comment.