format display of rss.xml with asp ??

B

btopenworld

I've looked over the last 2000 posts for info on incorportating an RSS feed
on a web page using ASP to control the display - especially which elements
are shown and how many items are shown.

I found a free ASP script that I hoped would do the job - and when its
working its great.

Howerver, It seems to work on some feeds and not others and occasionally
stops working even though it was working.

When not working, a test of 'RSSitemsCount' shows as '-1' - it is finding
no items in the xml - even though they are there.

Any thoughts greatly appreciated.

Here is the code in question - (I've added a little html formatting and I am
styling with css)

<%
' =========== RSS2HTML.ASP for ASP/ASP.NET ==========
' copyright 2005 (c) www.Bytescout.com
' ===============================================

' =========== configuration =====================
' ##### URL to RSS Feed to display #########
URLToRSS = "http://rssnewsapps.ziffdavis.com/tech.xml"

' ##### max number of displayed items #####
MaxNumberOfItems = 7

' ##### Main template constants
MainTemplateHeader = "<table>"
MainTemplateFooter = "</table>"
' #####

' ##### Item template.
' ##### {LINK} will be replaced with item link
' ##### {TITLE} will be replaced with item title
' ##### {DESCRIPTION} will be replaced with item description
ItemTemplate = "<tr><td><a href=" & """{LINK}""" &
">{TITLE}</a><BR>{DESCRIPTION}</td></tr>"

' ##### Error message that will be displayed if not items etc
ErrorMessage = "Error has occured while trying to process " &URLToRSS &
"<BR>Please contact web-master"

' ================================================

Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
xmlHttp.Open "Get", URLToRSS, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText

Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
xmlDOM.async = false
xmlDOM.LoadXml(RSSXML)

Set xmlHttp = Nothing ' clear HTTP object

Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items"
from downloaded RSS
Set xmlDOM = Nothing ' clear XML

RSSItemsCount = RSSItems.Length-1

' writing Header
if RSSItemsCount > 0 then
Response.Write MainTemplateHeader
End If

j = -1

For i = 0 To RSSItemsCount
Set RSSItem = RSSItems.Item(i)

for each child in RSSItem.childNodes
Select case lcase(child.nodeName)
case "title"
RSStitle = child.text
case "link"
RSSlink = child.text
case "description"
RSSdescription = child.text
End Select
next

j = J+1

if J<MaxNumberOfItems then
ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription)
ItemContent = ""
End if

Next

' writing Footer
if RSSItemsCount > 0 then
Response.Write MainTemplateFooter
else
Response.Write ErrorMessage
End If

' Response.End ' uncomment this line if you need to finalize output
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top