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

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

new
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture


dailyclick
All times in EST

Full Schedule
g
g ASP Site

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.
Add Enhanced+RSS+Code+using+ASP to Twitter Add Enhanced+RSS+Code+using+ASP to Facebook Add Enhanced+RSS+Code+using+ASP to MySpace Add Enhanced+RSS+Code+using+ASP to Del.icio.us Digg Enhanced+RSS+Code+using+ASP Add Enhanced+RSS+Code+using+ASP to Yahoo My Web Add Enhanced+RSS+Code+using+ASP to Google Bookmarks Add Enhanced+RSS+Code+using+ASP to Stumbleupon Add Enhanced+RSS+Code+using+ASP to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


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


Content copyright © 2014 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 Lisa Shea for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


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


BellaOnline Editor