g
Printer Friendly Version

editor  
BellaOnline's ASP Editor
 

News Feed using RSS

News feed using RSS

Creating news articles is probably the one thing that really pushed RSS to its popularity. News in its basic definition is to inform and educate based on facts. Now that is not to say the news sometimes has opinions added to the mix. Either way, the electronic masses needed to get their articles out in a way for all to read and to get them when they were published. Enter RSS.

Using RSS to feed news is one of the most easiest ways to inform your readers of what is going on. As mentioned in my previous articles, you may want to build a front end interface, using ASP of course, to enter your news articles into your database. Having this front end will allow you to easily enter any new articles and not have to worry about getting into the database to enter them manually.

There are two parts to creating the RSS feed.

The header and the body. The header consist of some basic RSS code to format the feed correctly so that is can be read and processed by the readers. (You can get a free one from www.RSSReader.com) The body will include the information that is pulled from the database.

Here is how the header will always look:

<?xml version="1.0"
encoding="ISO-8859-1"?>

<% Response.Buffer = true
Response.ContentType = "text/xml"
Function ApplyXMLFormatting(strInput)
if len(strInput) > 0 then
strInput =
Replace(strInput,"&", "&")

strInput = Replace(strInput,"'", "'")
strInput = Replace(strInput,"""",
""")

strInput = Replace(strInput, ">",
">")

strInput = Replace(strInput,"<","<")
else
strInput = ""
end if
ApplyXMLFormatting = strInput
End Function
%>

Again, this will make sure that the RSS Reader can read the file correctly. The next piece is the body which will process the news records from the database. As long as you have the fields setup in the database, you should be good to go. (http://www.bellaonline.com/articles/art46418.asp)

The body of the file can look like this:

<rss version="2.0">
<channel>
<title>RSS Job Board -
ASP</title>

<link>http://asp.bellaonline.com</link>
<description>RSS Job Board for
ASP Developers</description>

<language>en-us</language>
<copyright>Copyright
2006</copyright>

<lastBuildDate><%=Now()%></lastBuildDate>
<ttl>20</ttl>
<image>
<url>http://www.bellaonline.com/images/bella.gif</url>
<title>ASP @ BellaOnline.com</title>
<link>http://asp.bellaonline.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 RSSTable
WHERE (DateAdded <= '" & Now() & "') order by DateAdded DESC"

objRS.Open strSQL, objConn

Do While Not objRS.EOF
strDesc = "<b>Job Posted by " &
objRS("Owner") & " on " & _

objRS("DateAdded") & "
PST</b><br>" & _

objRS("Message").Value
%>

<item>
<title><%=ApplyXMLFormatting(objRS("ShortDesc").Value)%>


</title>
<link>http://asp.bellaonline.com</link>
<description><%=ApplyXMLFormatting(strDesc)%></description>
<guid><%=objRS("ID")%></guid>
<datePosted><%=objRS("DateAdded")%></datePosted>
<webMaster>asp@bellaonline.com
(Christopher Combs)</webMaster>

<author><%=objRS("Owner")%></author>
<comments>http://asp.bellaonline.com</comments>
<pubDate><%=objRS("DateAdded")%></pubDate></item><%
objRS.MoveNext
Loop
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%></channel></rss>
Then save the file as an ASP or an RSS. (RSS making sure you have setup your server to accept RSS file requests as ASP http://www.bellaonline.com/articles/art30642.asp)

If you have problems or questions regarding this or any other article, please let me know. asp@bellaonline.com

This site needs an editor - click to learn more!

ASP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 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 Editor Wanted for details.



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


BellaOnline Editor