Bruce Phillips asked me about the code I used to generate the XML that feeds Surfing Stats. I wanted to look it over before I released it, thinking I would clean it up some. Plus, there was an annoying order bug I wanted to fix. I've fixed it now and am ready for others to use the code as they see fit.
How It Works
When a request comes in, statsexport.cfm looks for a value in the url scope called dataset which then is evaluated inside a large switch statement. If the passed value matches a case, then one or more queries are run. If not, the default case runs and an empty query is generated. The Blog Totals dataset actually runs a number of queries and uses the fancy Query functions in ColdFusion (QueryNew, QuerySetCell etc) to create and populate a query. (I used the queries that were in the stats.cfm page so there should be no difference between the table structure of your blog and mine.)
At the very bottom of the page we:
- reset the content (XML hates stray whitespace)
- convert the query to XML using queryToXML by Nathan Dintenfass
- set the content type to text/xml
- return the response to the client
You can download the file using the download link at the end of this post. I've also included it in the latest SurfingStats zip file located at the download link at the bottom of the Intro to Surfing Stats post. If you make something interesting with this file, let me know.