logo
g Text Version
Auto
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Society & Culture
Sports
Travel & Leisure
TV & Movies

dailyclick
Bored? Games!
Postcards
Astrology
Take a Quiz
Rate My Photo

new
Jokes & Riddles
Astronomy
Philosophy
Public Health
Canadian Culture


dailyclick
All times in EST

Low Carb: 8:00 PM

Full Schedule
g
g ASP Site
Editor Wanted
BellaOnline's ASP Editor

g

Enhanced RSS Code using ASP
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"
Function applySpecialFormat(strInput)
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;
else
strInput = ""
end if
applySpecialFormat = strInput
End Function
%>
<rss version="2.0">
<channel>
<title>RSS using ASP Code</title>
<link>http://www.myserver.com</link>
<description>RSS Using ASP code to view new and existing articles from a database.</description>
<language>en-us</language>
<copyright>Copyright 2006</copyright>
<lastBuildDate><%=Now()%></lastBuildDate>
<ttl>20</ttl>
<image>
<url>http://www.myserver.com/images/logo.jpg</url>
<title>RSS using ASP Code Logo</title>
<link>http://www.myserver.com</link>
</image>
<%
Dim objConn
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
objConn.Open

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>" & _
objRS("ArticleContent").Value %>
<item>
<title><%= applySpecialFormat (objRS("ShortDesc").Value)%>
(<%=applySpecialFormat (objRS("AddedBy").Value)%>)
</title>
<link>http://www.myserver.com/article_view.asp?ArticleID=<%=objRS("ArticleID")%></link>
<description><%= applySpecialFormat (strDesc)%></description>
<guid><%=objRS("ArticleID")%></guid>
<datePosted><%=objRS("AddedDate")%></datePosted>
<webMaster>asp@bellaonline.com (Christopher Combs)</webMaster>
<author><%=objRS("AddedBy")%></author>
<comments>DOUBLE CLICK HERE TO ACCESS THE LINK FOR THE ATTACHMENT DOWNLOAD</comments>
<source url="http://www.myserver.com/articlesver2.rss">Article Source</source>
<pubDate><%=objRS("AddedDate")%></pubDate>
</item>
<%
objRS.MoveNext
Loop
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>
</channel>
</rss>


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.

This site needs an editor - click to learn more!

RSS | Related Articles | Previous Features | Site Map


Content copyright © 2008 by Christopher Combs. All rights reserved.
This content was written by Christopher Combs. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

Digg! g delicious Save to Del.icio.us

g


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor

g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Driving Amount
Much more
Slightly more
Slightly less
Much less

g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2008 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor