Ralpharama Archive. The archive is almost 20 years old, this website is no longer maintained.

Home | New Writing | Old Writing | Cooking | Technical | Wine Making | Cocktails
   
 
Misc

Classic ASP XML Feed Reader

Hits 21804 | Created 2007-07-05 | Modified 2009-01-23

No bells, no whistles, just a classic, no fuss feed reader. If you find that the feed is always unavailable, it may be badly formed, or you may have a problem with the way your server is configured.

Function showFeed(url)
	Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
	xmlObj.async = False
	xmlObj.setProperty "ServerHTTPRequest", True
	xmlObj.Load(url)
	If xmlObj.parseError.errorCode <> 0 Then
		Response.Write "Sorry, newsfeed is unavailable"
	End If
	Set xmlList = xmlObj.getElementsByTagName("item")
	Set xmlObj = Nothing
	For Each xmlItem In xmlList
		Response.Write ""
		Response.Write xmlItem.childNodes(0).text
		Response.Write xmlItem.childNodes(1).text
	Next
	Set xmlList = Nothing
End Function
showFeed("http://news.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml") 


You'll need to check the format of the feed you want to read - if it has items within a channel then you can access each element using the childNode(x) where x is the number in the item. Play around, you'll get it.

This is taken, mostly, then fiddled with from the fine MegaTokyo example found here: http://www.asp101.com/articles/john/megatokyo/dotnet.asp

Improved version (some time later :)

Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlObj.async = False
xmlObj.setProperty "ServerHTTPRequest", True
xmlObj.Load(url)
If xmlObj.parseError.errorCode <> 0 Then
	toReturn = toReturn & "Feed temporarily unavailable <em>(" _
	& xmlObj.parseError.reason&")</em><br>"
End If
Set xmlList = xmlObj.getElementsByTagName("item")
Set xmlObj = Nothing
For Each xmlItem In xmlList
	For Each xmlItem2 In xmlItem.childNodes
		a = xmlItem2.nodeName
		if a = "title" then title=xmlItem2.text
		if a = "link" then link=xmlItem2.text
		if a = "description" then description=xmlItem2.text
	Next
Next




Comment Classic ASP XML Feed Reader comment by Rogee Hits | Last Modified 2009-01-27
This is great... thank you!
Comment Classic ASP XML Feed Reader comment by diego Hits | Last Modified 2009-09-17
good work. Thanks !!
Comment Classic ASP XML Feed Reader comment by ninjaGUY Hits | Last Modified 2010-02-06
Thanks, this solved my problem

Make a Comment

Name
Comment


Antispam Code (always a number)

Enter Code Above
Submit

Note: All HTML will be removed except for bold and italics. Links will not display. Line breaks are added automatically. Use <pre>...</pre> for code.

Tags

This item has the following tags:
tech rss xml feed reader asp vbscript

Useful? Donate for hosting costs

All content copyright (c) Ralpharama