24Apr/067
ASP: Easily Parse and Consume RSS in Classic ASP
This script should work right out of the box..
<%
Call getNews(10)
Sub getNEWS(howManyResults)
myRSSfile = "http://rss.news.yahoo.com/rss/tech"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.4.0")
xmlHttp.Open "Get", myRSSfile, false
xmlHttp.Send()
myXML = xmlHttp.ResponseText
Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlResponse.async = false
xmlResponse.LoadXml(myXML)
Set xmlHttp = Nothing
Set objLst = xmlResponse.getElementsByTagName("item")
Set xmlResponse = Nothing
intNoOfHeadlines = objLst.length -1
For i = 0 To (intNoOfHeadlines)
Set objHdl = objLst.item(i)
for each child in objHdl.childNodes
Select case lcase(child.nodeName)
case "title"
title = child.text
case "link"
link = child.text
case "description"
description = child.text
'You can also use the following: author,category,comments,enclosure,guid,pubDate,source
End Select
next
kk = kk+1
if kk < howManyresults+1 then
Response.Write "<br /><a href=""" & link & """>" & title & "</a> <br /> " & description
end if
Next
End Sub
%>



May 25th, 2006 - 11:02
Nice little example of XML parsing…couple of things I noticed;
myXML = xmlHttp.ResponseText
xmlResponse.LoadXml(myXML)
by loading the responseText into a variable you immediately convert the encoding into UTF-8..fine for most US feeds but anything with a UK pound sign (£) in it wil fail even though its a valid character…many of these feeds are give an ISO-8859-1 charset encoding.
Can do;
xmlResponse.Load xmlHttp.responseXML
in one step instead…however this means that you will not be able to do any processing on the XML if it is formed badly..such as the notoriously terrible feeds from TheRegister which are full of unescaped &chars and html tags etc.
Thanks
Rolf
July 6th, 2008 - 13:18
Super, but it would be nice to see some XSLT transformations, purely from a style perspective. Other than that, good stuff.
December 13th, 2008 - 01:45
When I try to run this code I get the following error:
error ’80004005′
Unspecified error
Any ideas on how I could correct this?
Thanks
March 27th, 2009 - 08:30
Nice piece of code. Thanks curly!
March 30th, 2009 - 10:47
Great code. Another comment is that if you are on IIS 6, you may have to change the references to version 4 to version 6 to get it to work.
Set xmlHttp = Server.CreateObject(“Msxml2.ServerXMLHTTP.6.0″)
xmlHttp.Open “Get”, myRSSfile, false
xmlHttp.Send()
myXML = xmlHttp.ResponseText
Set xmlResponse = Server.CreateObject(“MSXML2.DomDocument.6.0″)
xmlResponse.async = false
xmlResponse.LoadXml(myXML)
Set xmlHttp = Nothing
May 5th, 2010 - 12:06
not working. hangs up browser.
June 21st, 2011 - 05:53
Now how about showing the exact OPPOSITE of this, and which is much more useful, and that is…an example in classic ASP that shows how to actually ADD a blog entry (as an item) or EDIT an <item> in the XML feed file. This would be extremely useful for folks that wrote their own blog pages in classic ASP with a SQL DB back end.