Thursday 13 September 2012

Creating RSS Feed in ASP


Creating RSS Feed in ASP
-----------------------------------------------------------------------------------------------------------
<%
Function ApplyXMLFormatting(strInput)
'strInput = Replace(strInput,"&", "&amp;")
'strInput = Replace(strInput,"'", "'")
'strInput = Replace(strInput,"""", "&quot;")
'strInput = Replace(strInput, ">", "&gt;")
'strInput = Replace(strInput,"<","&lt;")
strInput = Replace(strInput,"&nbsp;"," ")
strInput = Replace(strInput,"&", " ")
strInput = Replace(strInput,"", " ")
strInput = Replace(strInput,"""", " ")
strInput = Replace(strInput, "<p>", " ")
strInput = Replace(strInput,"</p>"," ")
strInput = Replace(strInput, "<P>", " ")
strInput = Replace(strInput,"</P>"," ")
strInput = Replace(strInput,"?","")
strInput = Replace(strInput,"<P align=left>"," ")
ApplyXMLFormatting = strInput
End Function
Function dateTimeToRFC1123(dt_dateTime)
dim a_shortDay, a_shortMonth
dt_dateTime = dateAdd ("N", server.createObject ("WScript.Shell").regRead ("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias") , dt_dateTime)
a_shortDay = array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
a_shortMonth = array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
dateTimeToRFC1123 = a_shortDay (weekDay (dt_dateTime) - 1) & ","
dateTimeToRFC1123 = dateTimeToRFC1123 & " " & right ("0" & day (dt_dateTime) , 2) & " " & a_shortMonth (month (dt_dateTime) - 1) & " " & year (dt_dateTime)
dateTimeToRFC1123 = dateTimeToRFC1123 & " " & right ("0" & hour (dt_dateTime) , 2) & ":" & right ("0" & minute (dt_dateTime) , 2) & ":" & right ("0" & second (dt_dateTime) , 2) & " GMT"
End Function

dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
dim path
path="C:\xmlpath\rss.xml"

set fname=fs.CreateTextFile(path,true)

fname.write("<?xml version='1.0'  encoding='UTF-8' standalone='yes'?>")
fname.write("<?xml-stylesheet href='http://sitename/rss.css' type='text/css'?>")
fname.write("<rss version='2.0'>")
fname.write("<channel>")
fname.write("<title>"&Sitename&" RSS</title>")
fname.write("<link>http://"&Sitename&"/</link>")
fname.write("<description>RSS for the "&Sitename&" community.</description>")
fname.write("<pubDate>"& dateTimeToRFC1123(now()) &"</pubDate>")
fname.write("<lastBuildDate>"& dateTimeToRFC1123(now()) &"</lastBuildDate>")
fname.write("<generator>SITE NAME RSS Generator 2.00</generator>")
fname.write("<language>en-us</language>")
fname.write("<image>")
fname.write("<link>http://"&Sitename&"/</link>")
fname.write("<title>SITE NAME TITLE</title>")
fname.write("<url>http://www.sitename.com/images/image.gif</url>")
fname.write("</image>")
fname.write("<div class='info' xmlns='http://www.w3.org/1999/xhtml'>This is formatted XML site feed. It is intended to be viewed in an RSS or Atom Newsreader or syndicated to another site.<br /></div>")

fname.write("<item>")
fname.write("<link>http://"&Sitename&"/"& LINK &"</link>")
fname.write("<pubDate>"& dateTimeToRFC1123(now()) &"</pubDate>")
fname.write("<guid>http://"&Sitename&"/"& LINK &"</guid>")
fname.write("<title>" &Server.HTMLEncode(SUBJECT)& "</title>")
fname.write("<description>" &Server.HTMLEncode(TOTALDESCRIPTION)& "</description>")
fname.write("</item>")

fname.write("</channel>")
fname.write("</rss>")
%>
-----------------------------------------------------------------------------------------------------------

No comments:

Post a Comment