Visit Sponsor

Written by 8:29 am ColdFusion, Flex

How I created a back-end XML service from BlogCFC

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:

  1. reset the content (XML hates stray whitespace)
  2. convert the query to XML using queryToXML by Nathan Dintenfass
  3. set the content type to text/xml
  4. return the response to the client

  5. #queryToXML(theQuery)#

    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.

    Visited 1 times, 1 visit(s) today
    [mc4wp_form id="5878"]
Close