Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how make rss from sql server

Status
Not open for further replies.

mayamanako

Technical User
Joined
Aug 31, 2005
Messages
113
Location
GB
hi folks, can you give me some ideas as to how to make an rss from a sql server db? i want to output the latest news from our site. thnx.
 
I've been breaking my links quite a bit lately.

apologies


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
hi onpnt, i believe that's how you gather rss feeds from other sites. what i want to do is to output my own rss feeds so that other sites can have our latest news. any help pls? thnx
 
RSS syntax is as follows:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0"><channel>
<title>W3Schools</title>
<link><description>W3Schools Web Tutorials </description><item>
<title>RSS Tutorial</title>
<link><description>Check out the RSS tutorial
on W3Schools.com</description>
</item></channel>
</rss>


Which bits need to be dynamic? Title, Link, Description. So store these three in your table with one field called ArticleID or something set to Autonumber. You might want to include a date field called DatePosted so that when you create the RSS file it only pulls records that have been posted in the last 30 days for example.

Then you need to connect to the database and select all the articles with the correct date range then create a string called Body which is going to hold the text above:

<%

rs.Open "SELECT ChannelTitle, ChannelLink, ChannelDescription, ItemTitle, ItemLink, ItemDescription FROM Articles", DB

Body=""
Body = Body & "<?xml version='1.0' encoding='ISO-8859-1' ?>"
Body = Body & "<rss version='2.0'>"
Body = Body & "<channel>"
Body = Body & "<title>" & TBL("ChannelTitle") %> & "</title>"
Body = Body & "<link>" & TBL("ChannelLink") & "</link>"
Body = Body & "<description>" & TBL("ChannelDescription") & "</description>"

Do While Not rs.EOF

Body = Body & "<item>"
Body = Body & "<title>" & TBL("ItemTitle") & "</title>"
Body = Body & "<link>" & TBL("ItemLink") & "</link>"
Body = Body & "<description>" & TBL("ItemDescription") & "</description>"
Body = Body & "</item>"

rs.MoveNext
Loop
</channel>
</rss>

rs.Close
Set rs=Nothing
Set DB=Nothing

Once you've created the string 'Body' you then need to write this to a file.

Set fs = CreateObject("Scripting.FileSystemObject")
Set wfile = fs.CreateTextFile("rssfeed.rss", True)

If Len(Body)>0 Then
wfile.Write(Body)
End If

wfile.close
Set wfile=nothing
Set fs=nothing

%>

You could set this script to run once a day as a scheduled task or install it as a service. Not sure if this is definitely the best approach or if this code all works exactly but hopefully is step in the right direction!

cheers

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top