QUESTIONS OR COMMENTS ABOUT PRODUCTS? WRITE US AT SUPPORT@BYTESCOUT.COM OR USE THIS FORM

Free ASP script: Learn how to display RSS/XML feed using free ASP script on ASP/ASP.NET web-server

How to display RSS/XML news feed in ASP/ASP.NET using RSS2HTML.ASP script

You can download the source code of this freeware rss2html.asp script here: asp_rss2html.zip

Looking for ASP script with mutiple RSS2HTML and better keywords filtering ?

Check our RSS2HTMLPro.ASP script for ASP/ASP.NET



This page provides quick guide for displaying of RSS/XML feed using free RSS2HTML ASP script in ASP or ASP.NET environment. This script can be used free of charge on any ASP or ASP.NET web-server and generate HTML from RSS feed.

This free ASP script uses MSXML to load RSS feed from URL and display it. You can use it standalone or call from script on HTML page to generate HTML content from RSS feed and then display on your HTML page.

Frequently Asked Questions new

<%

Response.Expires = -1

' =========== RSS2HTML.ASP for ASP/ASP.NET ==========

' copyright 2005-2008 (c) www.Bytescout.com

' version 1.27, 16 August 2008

' =========== configuration =====================

' ##### URL to RSS Feed to display #########

URLToRSS = "http://feeds2.feedburner.com/Bytescout"

' ##### max number of displayed items #####

MaxNumberOfItems = 7

' ##### Main template constants

MainTemplateHeader = "<table>"

MainTemplateFooter = "</table>"

' #####

' ######################################

Keyword1 = "" ' Keyword1 = "tech" - set non-empty keyword value to filter by this keyword

Keyword2 = "" ' Keyword1 = "win" - set non-empty keyword value to filter by this 2nd keyword too

' #################################

' ##### Item template.

' ##### {LINK} will be replaced with item link

' ##### {TITLE} will be replaced with item title

' ##### {DESCRIPTION} will be replaced with item description

' ##### {DATE} will be replaced with item date and time

' ##### {COMMENTSLINK} will be replaced with link to comments (if you use RSS feed from blog)

' ##### {CATEGORY} will be replaced with item category

ItemTemplate = "<tr><td><strong>{DATE}</strong><br/><strong>{CATEGORY}<br/></strong><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.ServerXMLHTTP.3.0")

xmlHttp.Open "GET", URLToRSS, false

xmlHttp.Send()

RSSXML = xmlHttp.ResponseText

Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")

xmlDOM.async = False

xmlDOM.validateOnParse = False

xmlDom.resolveExternals = False

If not xmlDOM.LoadXml(RSSXML) Then

ErrorMessage = "Can not load XML:" & vbCRLF & xmlDOM.parseError.reason & vbCRLF & ErrorMessage

End If

Set xmlHttp = Nothing ' clear HTTP object

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

RSSItemsCount = RSSItems.Length-1

' if not <item>..</item> entries, then try to get <entry>..</entry>

if RSSItemsCount = -1 Then

Set RSSItems = xmlDOM.getElementsByTagName("entry") ' collect all "entry" (atom format) from downloaded RSS

RSSItemsCount = RSSItems.Length-1

End If

Set xmlDOM = Nothing ' clear XML



' writing Header

if RSSItemsCount > 0 then

Response.Write MainTemplateHeader

End If

j = -1

For i = 0 To RSSItemsCount

Set RSSItem = RSSItems.Item(i)

' fix for the issue when a description from a previous item

' is used if current item description is empty provided by George Sexton

RSSdescription="&nbsp;"

RSSCommentsLink="&nbsp;"

for each child in RSSItem.childNodes

Select case lcase(child.nodeName)

case "title"

RSStitle = child.text

case "link"

If child.Attributes.length>0 Then

RSSLink = child.GetAttribute("href")

if (RSSLink <> "") Then

if child.GetAttribute("rel") <> "alternate" Then

RSSLink = ""

End If

End If

End If ' if has attributes

If RSSLink = "" Then

RSSlink = child.text

End If

case "description"

RSSdescription = child.text

case "content" ' atom format

RSSdescription = child.text

case "published"' atom format

RSSDate = child.text

case "pubdate"

RSSDate = child.text

case "comments"

RSSCommentsLink = child.text

case "category"

Set CategoryItems = RSSItem.getElementsByTagName("category")

RSSCategory = ""

for each categoryitem in CategoryItems

if RSSCategory <> "" Then

RSSCategory = RSSCategory & ", "

End If

RSSCategory = RSSCategory & categoryitem.text

Next

End Select

next

' now check filter

If (InStr(RSSTitle,Keyword1)>0) or (InStr(RSSTitle,Keyword2)>0) or (InStr(RSSDescription,Keyword1)>0) or (InStr(RSSDescription,Keyword2)>0) then

j = J+1

if J<MaxNumberOfItems then

ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)

ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)

ItemContent = Replace(ItemContent,"{DATE}",RSSDate)

ItemContent = Replace(ItemContent,"{COMMENTSLINK}",RSSCommentsLink)

ItemContent = Replace(ItemContent,"{CATEGORY}",RSSCategory)

Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription)

ItemContent = ""

RSSLink = ""

End if

End If

Next

' writing Footer

if RSSItemsCount > 0 then

Response.Write MainTemplateFooter

else

Response.Write ErrorMessage

End If

' Response.End ' uncomment this for use in on-the-fly output

%>

 

2) Save RSS2HTML.asp and place "RSS2HTML.asp" into root folder of your web-server. (This folder is C:\Inetpub\wwwroot\ by default if you use Internet Information Service (IIS) on Windows 2000 and XP)

  [an error occurred while processing this directive]

3) Now open "http://localhost/RSS2HTML.asp" (or "http://<your_webserver_name>/RSS2HTML.asp") in Internet Explorer browser. You will see HTML page generated from RSS provided in URLtoRSS varaiable in RSS2HTML.ASP script above:

 
HTML content generated by free RSS2HTML script for ASP
 

To include this script into existing page use virtual include ASP command. For example you can include generated HTML it into MyPage.asp like this:

< html>

< body>

< p>My Page</p>

< p>RSS content is displayed below:</p>

< hr>

< !--#include virtual="RSS2HTML.asp"-->

< hr>

< /body>

< /html>

You can download the source code of this example here: asp_rss2html.zip

If you want to display filtered RSS feeds using customizable keywords please check RSS2HTML Scout library for ASP and ASP.NET

If you like our free RSS2HTML script for ASP and you use it we would appreciate if you will place link to this page somewhere on your web-site so another ASP web-masters will be able to find this free script.

If you like RSS2HTML.asp script then spread the word by copying and pasting this HTML code below:

Looking for ASP script with mutiple RSS2HTML and better keywords filtering ?

Check our RSS2HTMLPro.ASP script for ASP/ASP.NET

Frequently Asked Questions: new

Q: How to display items in backward order? new

A: Try to replace  

For i = 0 To RSSItemsCount

with

For i = RSSItemsCOunt To 0 Step -1

 

Q: I have RSS feed and it worked fine. But suddenly script returns errors new

A: Our script relies on MSXML control library. So do the following steps:

- check if you have the latest MSXML installed: http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&DisplayLang=en

- check if RSS feed is error free. Check RSS feed using these free RSS feed validation services:

http://feedvalidator.org/
| http://www.ldodds.com/rss_validator/1.0/validator.html | http://validator.w3.org/feed/

Inform web-master of RSS feed to fix errors in RSS feed.

Q: How to open links in new browser window?

A: Change ItemTemplate like this

ItemTemplate = "<tr><td><font size=1><a href=" & """{LINK}""" & " target='_blank'>{TITLE}</a></font><BR><font size=-2>{DESCRIPTION}</font></td></tr>"

Q: How to change font size for the displayed items?

A: Change ItemTemplate. For example:

ItemTemplate = "<tr><td><font size=1><a href=" & """{LINK}""" & ">{TITLE}</a></font><BR><font size=-2>{DESCRIPTION}</font></td></tr>"

Q: How to filter items using predefined keywords?

A: Modify script like this

Please try to modify RSS2HTML.asp script to something like this:

MyKeyword = "Computer"



....

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

bSkip = FALSE



' checking title

if inStr(UCase(RSSTitle), UCase(MyKeyword))=0 Then

bSkip = TRUE

End If

' checking title

If bSkip Then

if inStr(UCase(RSSDescription), UCase(MyKeyword))>0 Then

bSkip = False

End If

End If

If Not bSkip Then

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

End If

Next