Guest Author - Christopher Combs
Warning – Cool Code Content Ahead!!
Here is what you need to do. Make sure you have your database created whether it is Access or SQL. Once you have that done, note your connection string and table names. For this exercise, I am going to use the following:
ArticleID – Automatic Number – this number will be incorporated into the link .(Use int with seed for SQL and autonumber for Access)
DateAdded – Date and Time the Article was added
AddedBy – Author of the article
ShortDesc – Simple description whether it is news or information type of article
ArticleContent – The actual news information for the article.
Now, with this version we will be applying the special XML formatting to make sure that when the RSS Reader gets the news articles, it won’t fail because of any special characters the reader cannot process. RSS with the XML format is very picky about what characters are processed but we will make sure that it can’t process any bad characters and we will call it applySpecialFormat function.
One more thing to note, if you want users to view the article when they click on the link in their reader, make sure you create a page that will show the Article and its information. You probably already have this but I just wanted to make sure I said it just in case. For this exercise, I will be using article_view.asp.
Now for the code: (Save the file as articlesver2.rss onto your web server.)
<?xml version="1.0" encoding="ISO-8859-1"?>
<% Response.Buffer = true
Response.ContentType = "text/xml"
if len(strInput) > 0 then
strInput = Replace(strInput,"&", "&")
strInput = Replace(strInput,"'", "& apos;") 'REMOVE SPACE BETWEEN & apos;
strInput = Replace(strInput,"""", "& quot;") 'REMOVE SPACE BETWEEN & quot;
strInput = Replace(strInput, ">", "& gt;") 'REMOVE SPACE BETWEEN & gt;
strInput = Replace(strInput,"<","& lt;") 'REMOVE SPACE BETWEEN & lt;
strInput = ""
applySpecialFormat = strInput
<title>RSS using ASP Code</title>
<description>RSS Using ASP code to view new and existing articles from a database.</description>
<title>RSS using ASP Code Logo</title>
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
objConn.ConnectionString = "Provider=sqloledb;Data Source=DBSERVER;Initial Catalog=ARTICLEDB;User Id=sa;Password=sqlpassword;"
objConn.CursorLocation = 3
Dim objRS, strSQL, strDesc
strSQL = "SELECT * FROM ArticleDB WHERE (AddedDate <= '" & Now() & "') order by AddedDate DESC"
objRS.Open strSQL, objConn
Do While Not objRS.EOF
strDesc = "<b>Article by " & objRS("AddedBy") & " on " & _
objRS("AddedDate") & " PST</b><br>" & _
<title><%= applySpecialFormat (objRS("ShortDesc").Value)%>
<description><%= applySpecialFormat (strDesc)%></description>
<webMaster>firstname.lastname@example.org (Christopher Combs)</webMaster>
<comments>DOUBLE CLICK HERE TO ACCESS THE LINK FOR THE ATTACHMENT DOWNLOAD</comments>
<source url="http://www.myserver.com/articlesver2.rss">Article Source</source>
Set objRS = Nothing
Set objConn = Nothing
Now, if you have created your tables and have added information to your database, you can test the file in your RSS Reader. I use a free reader from www.rssreader.com. It allows me to see all the options I can use in the RSS feed and it will tell me if there are any errors when processing it.
Speaking of errors, if there are any, simply paste the URL of the RSS file into your web browser and it should tell you what line number the error is on which in turn allows you to correct the problem. (To see error messages, ensure that you have turned off the “friendly messages” for ASP – See Microsoft’s TechNet article
Turn Off Friendly Messages) Most errors that I usually come across are syntax errors which means you need to apply the formatting to the output of your RSS file.
That is it! Keep your eyes open for more articles on RSS and how it can be a valuable tool.