Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2007, 09:50 PM   PM User | #1
telmessos
Regular Coder

 
Join Date: Apr 2006
Posts: 127
Thanks: 6
Thanked 0 Times in 0 Posts
telmessos is an unknown quantity at this point
Creating an RSS (or XML) file with ASP

Hi all,

I have a database of 1000 properties. I would like to create an ASP or possibly a VBS file which will execute daily at a certain time, delete the old XML file, create a new XML file and write the RSS information it gets from the database with a loop. How can I create file and write information? Any ideas or examples?

Thanks
telmessos is offline   Reply With Quote
Old 09-14-2007, 11:47 PM   PM User | #2
miranda
Senior Coder

 
Join Date: Dec 2002
Location: Arlington, Texas USA
Posts: 1,062
Thanks: 4
Thanked 8 Times in 8 Posts
miranda is an unknown quantity at this point
Use the File System Object to create your XML file.
Code:
<%
Dim FilePath
Dim FileName
Dim oFSO
Dim oNewFile

FilePath ="The_location_on_the_server_where_you_are_going_to_save_the_file_goes_here"
FileName = "The_name_of_the_file_goes_here"

Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oNewFile = oFSO.CreateTextFile(FilePath & FileName)

oNewFile.WriteLine"<?xml version=""1.0"" ?>"
oNewFile.WriteLine"<rss version=""2.0"">"
oNewFile.WriteLine"<channel>"
sSQL = "SELECT link, description, guid FROM YourDB"
oRs.Open sSQL, YourConnection
Do Until oRs.Eof
	oNewFile.WriteLine"<item>"
	oNewFile.WriteLine"<link>" & oRs("link") & "</link>"
	oNewFile.WriteLine"<description>" & oRs("description") & "</description>"
	oNewFile.WriteLine"<pubDate>" & Now() & "</pubDate>"
	oNewFile.WriteLine"<guid>" & oRs("guid") & "</guid>"
	oNewFile.WriteLine"</item>"
	Loop
oRs.MoveNext
oRs.Close
Set oRs = Nothing

oNewFile.WriteLine"</channel>"
oNewFile.WriteLine"</rss>"

oNewFile.Close
Set oFSO = Nothing 
%>
miranda is offline   Reply With Quote
Old 09-15-2007, 11:45 AM   PM User | #3
telmessos
Regular Coder

 
Join Date: Apr 2006
Posts: 127
Thanks: 6
Thanked 0 Times in 0 Posts
telmessos is an unknown quantity at this point
Thanks Miranda... You are a star...
telmessos is offline   Reply With Quote
Old 09-15-2007, 11:57 AM   PM User | #4
telmessos
Regular Coder

 
Join Date: Apr 2006
Posts: 127
Thanks: 6
Thanked 0 Times in 0 Posts
telmessos is an unknown quantity at this point
Do you also know how I can create the "Sat, 07 Sep 2002 09:42:31 GMT" format for pubDate element of RSS2.0?
telmessos is offline   Reply With Quote
Old 09-16-2007, 07:33 PM   PM User | #5
miranda
Senior Coder

 
Join Date: Dec 2002
Location: Arlington, Texas USA
Posts: 1,062
Thanks: 4
Thanked 8 Times in 8 Posts
miranda is an unknown quantity at this point
Assuming you are using SQL Server 2000 you can get the date/time as the GMT time.
So now your SQL Query would be
Code:
sSQL = "SELECT link, description, GETUTCDATE() AS UTCTime, guid FROM YourDB"
You can then format the string by writing a function similar to this one to actually display the string
Code:
Public Function ConvertToRSSDate(UTCTime)
	TheDate = WeekdayName(UTCTime,true) & ", " & Day(UTCTime) &  " " & _
		MonthName(DatepaPart("mm",UTCTime),true) & " " & Year(UTCTime) &  " " & _
		Hour(UTCTime) &  ":" & Minute(UTCTime) &  ":" &  Second(UTCTime) & " GMT"
	
	ConvertToRSSDate = TheDate
End Function
Final code might look something like this
Code:
Public Function ConvertToRSSDate(UTCTime)
	TheDate = WeekdayName(UTCTime,true) & ", " & Day(UTCTime) &  " " & _
		MonthName(DatepaPart("mm",UTCTime),true) & " " & Year(UTCTime) &  " " & _
		Hour(UTCTime) &  ":" & Minute(UTCTime) &  ":" &  Second(UTCTime) & " GMT"
	
	ConvertToRSSDate = TheDate
End Function


Dim FilePath
Dim FileName
Dim oFSO
Dim oNewFile

FilePath ="The_location_on_the_server_where_you_are_going_to_save_the_file_goes_here"
FileName = "The_name_of_the_file_goes_here"

Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oNewFile = oFSO.CreateTextFile(FilePath & FileName)

oNewFile.WriteLine"<?xml version=""1.0"" ?>"
oNewFile.WriteLine"<rss version=""2.0"">"
oNewFile.WriteLine"<channel>"
sSQL = "SELECT link, description, GETUTCDATE() AS UTCTime, guid FROM YourDB"
oRs.Open sSQL, YourConnection
Do Until oRs.Eof
    sDate = oRs("UTCTime")
	oNewFile.WriteLine"<item>"
	oNewFile.WriteLine"<link>" & oRs("link") & "</link>"
	oNewFile.WriteLine"<description>" & oRs("description") & "</description>"
	oNewFile.WriteLine"<pubDate>" & ConvertToRSSDate(sDate) & "</pubDate>"
	oNewFile.WriteLine"<guid>" & oRs("guid") & "</guid>"
	oNewFile.WriteLine"</item>"
	Loop
oRs.MoveNext
oRs.Close
Set oRs = Nothing

oNewFile.WriteLine"</channel>"
oNewFile.WriteLine"</rss>"

oNewFile.Close
Set oFSO = Nothing
miranda is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:27 PM.


Advertisement
Log in to turn off these ads.