Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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 
    %>

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks Miranda... You are a star...

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Do you also know how I can create the "Sat, 07 Sep 2002 09:42:31 GMT" format for pubDate element of RSS2.0?

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •