TexasWebDevelopers
Posts: 722 Joined: 2/22/2002 From: Dallas, TX Status: offline
|
RE: XML with ASP as RSS - 8/28/2008 17:34:15
We've written a bit of code that takes the title, date, and text from newly created blog entry and generates a new rss.xml file on the fly (pulling other blog entries from a database) using the file scripting object. You don't need anything this complicated but I thought the code might help you walk through the process if you want to do something like this yourself. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Response.Buffer = False %>
<!--#include file="database_connection.asp" -->
<%
Dim rsConfig
Dim rsConfig_numRows
Set rsConfig = Server.CreateObject("ADODB.Recordset")
rsConfig.ActiveConnection = MM_blog_STRING
rsConfig.Source = "SELECT * FROM BlogRSStable"
rsConfig.CursorType = 0
rsConfig.CursorLocation = 2
rsConfig.LockType = 1
rsConfig.Open()
rsConfig_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Update RSS</title>
</head>
<body>
<%
Dim artRec
Dim artRec_numRows
Set artRec = Server.CreateObject("ADODB.Recordset")
artRec.ActiveConnection = MM_blog_STRING
artRec.Source = "SELECT * FROM BlogRSStable, tableCat, tableAuthor WHERE BlogCat = CatID AND tableBlog.BlogAuthor = tableAuthor.fldAuthorID AND tableBlog.BlogDraft <> 1 ORDER BY BlogDate DESC"
artRec.CursorType = 0
artRec.CursorLocation = 2
artRec.LockType = 1
artRec.Open()
artRec_numRows = 0
sFilename = "D:\Inetpub\wwwroot\read-write-folder\rss.xml"
Dim objFSO
Dim fsoFile
' create an instance of the FileSystemObject
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
' create file
Set fsoFile = objFSO.CreateTextFile ((sFilename))
Dim objRS__currentDate
objRS__currentDate = "Month(Date())"
If (Month(Date()) <> "") Then
objRS__currentDate = Month(Date())
End If
Dim rsBlogConfig
Dim rsBlogConfig_numRows
Set rsBlogConfig = Server.CreateObject("ADODB.Recordset")
rsBlogConfig.ActiveConnection = MM_blog_STRING
rsBlogConfig.Source = "SELECT * FROM tblBlogRSS"
rsBlogConfig.CursorType = 0
rsBlogConfig.CursorLocation = 2
rsBlogConfig.LockType = 1
rsBlogConfig.Open()
rsBlogConfig_numRows = 0
function Do_StripHTML(strtext)
on error resume next
'Strips the HTML tags from strHTML
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<(.|\n)+?>"
'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strtext, "")
Set objRegExp = Nothing
strOutput = replace(strOutput,""",""")
strOutput = replace(strOutput,"'","'")
strOutput = replace(strOutput,"&","&")
strOutput = replace(strOutput,"<","<")
strOutput = replace(strOutput,">",">")
strOutput = replace(strOutput," "," ")
strOutput = replace(strOutput,"–","–")
strOutput = replace(strOutput,"—","—")
strOutput = replace(strOutput,"‘","‘")
strOutput = replace(strOutput,"’","’")
strOutput = replace(strOutput,"‚","‚")
strOutput = replace(strOutput,"“","“")
strOutput = replace(strOutput,"”","”")
strOutput = replace(strOutput,"„","„")
strOutput = replace(strOutput,"†","†")
strOutput = replace(strOutput,"‡","‡")
strOutput = replace(strOutput,"…","…")
strOutput = replace(strOutput,"¡","¡")
strOutput = replace(strOutput,"¤","¤")
strOutput = replace(strOutput,"¢","¢")
strOutput = replace(strOutput,"£","£")
strOutput = replace(strOutput,"¥","¥")
strOutput = replace(strOutput,"¦","¦")
strOutput = replace(strOutput,"§","§")
strOutput = replace(strOutput,"¨","¨")
strOutput = replace(strOutput,"©","©")
strOutput = replace(strOutput,"ª","ª")
strOutput = replace(strOutput,"«","«")
strOutput = replace(strOutput,"¬","¬")
strOutput = replace(strOutput,"","")
strOutput = replace(strOutput,"®","®")
strOutput = replace(strOutput,"™","™")
strOutput = replace(strOutput,"¯","¯")
strOutput = replace(strOutput,"°","°")
strOutput = replace(strOutput,"±","±")
strOutput = replace(strOutput,"²","²")
strOutput = replace(strOutput,"³","³")
strOutput = replace(strOutput,"´","´")
strOutput = replace(strOutput,"µ","µ")
strOutput = replace(strOutput,"¶","¶")
strOutput = replace(strOutput,"·","·")
strOutput = replace(strOutput,"¸","¸")
strOutput = replace(strOutput,"¹","¹")
strOutput = replace(strOutput,"º","º")
strOutput = replace(strOutput,"»","»")
strOutput = replace(strOutput,"¼","¼")
strOutput = replace(strOutput,"½","½")
strOutput = replace(strOutput,"¾","¾")
strOutput = replace(strOutput,"¿","¿")
strOutput = replace(strOutput,"×","×")
strOutput = replace(strOutput,"÷","÷")
strOutput = replace(strOutput,"À","À")
strOutput = replace(strOutput,"Á","Á")
strOutput = replace(strOutput,"Â","Â")
strOutput = replace(strOutput,"Ã","Ã")
strOutput = replace(strOutput,"Ä","Ä")
strOutput = replace(strOutput,"Å","Å")
strOutput = replace(strOutput,"Æ","Æ")
strOutput = replace(strOutput,"Ç","Ç")
strOutput = replace(strOutput,"È","È")
strOutput = replace(strOutput,"É","É")
strOutput = replace(strOutput,"Ê","Ê")
strOutput = replace(strOutput,"Ë","Ë")
strOutput = replace(strOutput,"Ì","Ì")
strOutput = replace(strOutput,"Í","Í")
strOutput = replace(strOutput,"Î","Î")
strOutput = replace(strOutput,"Ï","Ï")
strOutput = replace(strOutput,"Ð","Ð")
strOutput = replace(strOutput,"Ñ","Ñ")
strOutput = replace(strOutput,"Ò","Ò")
strOutput = replace(strOutput,"Ó","Ó")
strOutput = replace(strOutput,"Ô","Ô")
strOutput = replace(strOutput,"Õ","Õ")
strOutput = replace(strOutput,"Ö","Ö")
strOutput = replace(strOutput,"Ø","Ø")
strOutput = replace(strOutput,"Ù","Ù")
strOutput = replace(strOutput,"Ú","Ú")
strOutput = replace(strOutput,"Û","Û")
strOutput = replace(strOutput,"Ü","Ü")
strOutput = replace(strOutput,"Ý","Ý")
strOutput = replace(strOutput,"Þ","Þ")
strOutput = replace(strOutput,"ß","ß")
strOutput = replace(strOutput,"à","à")
strOutput = replace(strOutput,"á","á")
strOutput = replace(strOutput,"â","â")
strOutput = replace(strOutput,"ã","ã")
strOutput = replace(strOutput,"ä","ä")
strOutput = replace(strOutput,"å","å")
strOutput = replace(strOutput,"æ","æ")
strOutput = replace(strOutput,"ç","ç")
strOutput = replace(strOutput,"è","è")
strOutput = replace(strOutput,"é","é")
strOutput = replace(strOutput,"ê","ê")
strOutput = replace(strOutput,"ë","ë")
strOutput = replace(strOutput,"ì","ì")
strOutput = replace(strOutput,"í","í")
strOutput = replace(strOutput,"î","î")
strOutput = replace(strOutput,"ï","ï")
strOutput = replace(strOutput,"ð","ð")
strOutput = replace(strOutput,"ñ","ñ")
strOutput = replace(strOutput,"ò","ò")
strOutput = replace(strOutput,"ó","ó")
strOutput = replace(strOutput,"ô","ô")
strOutput = replace(strOutput,"õ","õ")
strOutput = replace(strOutput,"ö","ö")
strOutput = replace(strOutput,"ø","ø")
strOutput = replace(strOutput,"ù","ù")
strOutput = replace(strOutput,"ú","ú")
strOutput = replace(strOutput,"û","û")
strOutput = replace(strOutput,"ü","ü")
strOutput = replace(strOutput,"ý","ý")
strOutput = replace(strOutput,"þ","þ")
strOutput = replace(strOutput,"ÿ","ÿ")
strOutput = replace(strOutput,"Œ","Œ")
strOutput = replace(strOutput,"œ","œ")
strOutput = replace(strOutput,"Š","Š")
strOutput = replace(strOutput,"š","š")
strOutput = replace(strOutput,"Ÿ","Ÿ")
strOutput = replace(strOutput,"ˆ","ˆ")
strOutput = replace(strOutput,"˜","˜")
strOutput = replace(strOutput," "," ")
strOutput = replace(strOutput," "," ")
strOutput = replace(strOutput," "," ")
strOutput = replace(strOutput,"","")
strOutput = replace(strOutput,"","")
strOutput = replace(strOutput,"","")
strOutput = replace(strOutput,"","")
strOutput = replace(strOutput,"‰","‰")
strOutput = replace(strOutput,"‹","‹")
strOutput = replace(strOutput,"›","›")
strOutput = replace(strOutput,"€","€")
strOutput = replace(strOutput,Chr(10),"")
strOutput = replace(strOutput,Chr(13),"")
strOutput = replace(strOutput,"&","&")
strOutput = replace(strOutput,"'","'")
strOutput = replace(strOutput,"§","§")
strOutput = replace(strOutput,"©","©")
strOutput = replace(strOutput,"®","®")
strOutput = replace(strOutput,"¦","¦")
Do_StripHTML = strOutput
End Function
Function return_RFC822_Date(myDate, offset)
Dim myDay, myDays, myMonth, myYear
Dim myHours, myMonths, mySeconds
myDate = CDate(myDate)
myDay = WeekdayName(Weekday(myDate),true)
myDays = Day(myDate)
myMonth = MonthName(Month(myDate), true)
myYear = Year(myDate)
myHours = zeroPad(Hour(myDate), 2)
myMinutes = zeroPad(Minute(myDate), 2)
mySeconds = zeroPad(Second(myDate), 2)
return_RFC822_Date = myDay&", "& _
myDays&" "& _
myMonth&" "& _
myYear&" "& _
myHours&":"& _
myMinutes&":"& _
mySeconds&" "& _
offset
End Function
Function zeroPad(m, t)
zeroPad = String(t-Len(m),"0")&m
End Function
twdSiteTitle = (rsBlogConfig.Fields.Item("blogTitle").Value)
twdSiteDescr = (rsBlogConfig.Fields.Item("blogDesc").Value)
twdSiteURL = (rsBlogConfig.Fields.Item("blogURL").Value)
if right(twdSiteURL, 1) <> "/" then
twdSiteURL = sSiteURL & "/"
end if
twdSiteDetails = ""
twdImageURL = (rsBlogConfig.Fields.Item("blogImage").Value)
twdFurtherReading = ""
twdAuthorNames = (rsBlogConfig.Fields.Item("blogAuthor").Value)
twdAuthorEmails = (rsBlogConfig.Fields.Item("blogEmail").Value)
fsoFile.WriteLine ("<?xml version=""1.0""?>")
'fsoFile.WriteLine ("<?xml-stylesheet type=""text/css"" href=""" & sSiteURL & "rss.css"" ?>")
fsoFile.WriteLine ("<!-- RSS generated by " & twdSiteTitle & " on " & Now() & " -->")
fsoFile.WriteLine ("<rss version=""2.0"" xmlns:atom=""http://www.w3.org/2005/Atom"">")
fsoFile.WriteLine ("<channel>")
fsoFile.WriteLine("<title>Blog Title</title>")
fsoFile.WriteLine("<atom:link href=""http://yourwebsite/read-write-folder/rss.xml"" rel=""self"" type=""application/rss+xml"" />")
fsoFile.WriteLine("<link>" & twdSiteURL & "</link>")
fsoFile.WriteLine("<description>Blog RSS feed</description>")
fsoFile.WriteLine("<language>en-us</language>")
fsoFile.WriteLine("<pubDate>Mon, 28 Jul 2008 09:00:00 GMT</pubDate>")
fsoFile.WriteLine("<lastBuildDate>" & return_RFC822_Date(Now(), "GMT") & "</lastBuildDate>")
fsoFile.WriteLine("<webMaster>yourname@yoursite.com</webMaster>")
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
artRec_numRows = artRec_numRows + Repeat1__numRows
While ((Repeat1__numRows <> 0) AND (NOT artRec.EOF))
fsoFile.WriteLine ("<item>")
fsoFile.WriteLine ("<title>" & (CropSentence(Do_StripHTML(artRec.Fields.Item("BlogHeadline").Value), 500, "...")) & "</title>")
fsoFile.WriteLine ("<link>" & sSiteURL & "permalink.asp?id=" & artRec.Fields.Item("BlogID").Value & "</link>")
fsoFile.WriteLine ("<guid isPermaLink=""true"">" & sSiteURL & "permalink.asp?id=" & artRec.Fields.Item("BlogID").Value & "</guid>")
fsoFile.WriteLine ("<description>" & (CropSentence(Do_StripHTML(artRec.Fields.Item("BlogHTML").Value), 250, "...")) & "</description>")
fsoFile.WriteLine ("<pubDate>" & return_RFC822_Date(artRec.Fields.Item("BlogDate").Value, "GMT") & "</pubDate>")
fsoFile.WriteLine("<category domain=""" & twdSiteURL & "archives_cat.asp?cat=" & artRec.Fields.Item("CatID").Value & """>" & artRec.Fields.Item("CatName").Value & "</category>")
fsoFile.WriteLine ("</item>")
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
artRec.MoveNext()
Wend
' Write out the End Channel Data tag and End RSS tag.
fsoFile.WriteLine ("</channel>")
fsoFile.WriteLine ("</rss>")
fsoFile.Close
Set fsoFile = Nothing
Set objFSO = Nothing
rsBlogConfig.Close()
Set rsBlogConfig = Nothing
artRec.Close()
Set artRec = Nothing
%>
</body>
</html>
<%
rsConfig.Close()
Set rsConfig = Nothing
%>
|