After we had created our code corner site we decided that we would like to add a RSS 2.0 feed to it. The site is generated using a BB3 board and at this stage they have not created a RSS feed add-on for it so we were left to do this on our own. This article shows you how to create a RSS feed with an MRS script.
Once you have created an mrs file in studio we need to setup the fileSystemObject to create our RSS file. This is done with the following code.
Dim oFSO, oFile Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFile = oFSO.CreateTextFile("C:tempMyFirstRSS.xml", True) ' Content of file goes here oFile.Close() Set oFSO = Null
In this example we are just creating the RSS file in our temporary decretory, but if we wanted to , we could make this a location on our website and then people would be able to subscribe to it. The first line in our RSS file is the XML declaration, we have to have this so that the feed will validate as XML. The code we need is
oFile.WriteLine("")
The next step is to set the RSS channel. to do this we need to open up the rss tag, and the channel tag, then all of our feed content goes inside these tags.
oFile.WriteLine("") oFile.WriteLine(" ")
Now to add the information about our feed.
oFile.WriteLine("Smarter Dimensions Code Corner ") oFile.WriteLine("http://CodeCorner.smarterDimensions.com/") oFile.WriteLine("No talk, just pure dimensions ") oFile.WriteLine("Fri, 3 July 2009 20:37:00 GMT ") oFile.WriteLine("en-us ")
The lastBuildDate should be the date and time that the feed was last changed. Dates in RSS feeds should comply to RFC 822. In CFML the DateFormat mask would be ddd, dd mmm yyyy and the TimeFormat would be HH:mm:ss. Dates should be offset to GMT. The lastBuildDate tag is not required but is highly recommended.
Next we have our items that we want to have in our feed. Each item must have a title, link, and description, publication date, and guid.
oFile.WriteLine("- ") oFile.WriteLine("
")MRS Script ") oFile.WriteLine("http://codecorner.smarterdimensions.com/item/123") oFile.WriteLine("http://codecorner.smarterdimensions.com/item/123 ") oFile.WriteLine("Sat, 4 July 2009 14:37:00 GMT ") oFile.WriteLine("Function to strip out html. ") oFile.WriteLine("
Make sure you escape any characters that might cause your XML to invalidate, these characters include <, >, & –
If you want to have HTML in your description then you need to enclose it in a CDATA section for example.
oFile.WriteLine("[CDATA[ HTML code goes here ]] ")
Next we need to close all the open tags that we have created so add the code
oFile.WriteLine("") oFile.WriteLine("")
And so there you have it … Your first RSS feed. The next thing you must do to make sure all your code is correct is to validate you feed. This can be done by entering the URL for your file into this site. http://feedvalidator.org/
Ok, so what could we use this all for. And why is it on this which is really all about Market Research Surveys, well what we were thinking was , you could add this code into the end of your surveys to produce RSS feeds on the number of completes to a survey or perhaps use it for red alerts where you need to flag customers as “AT RISK”. The great thing about this is that you don’t have to setup any schedules or anything like that on your server, it can all be left down to the RSS reader on the recipients phone or email system !!!