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. view plain print about
    1<cfcontent reset="true" type="text/xml"><cfoutput>#queryToXML(theQuery)#</cfoutput>

    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.

    Download Download

    There are no comments for this entry.

    Add Comment Subscribe to Comments

    5/18/08 1:26 PM # Posted By Joseg Kreig

    Thank you for sharing this info. it was useful


    6/11/08 6:23 AM # Posted By polase

    Thank you for showing this technique. I've been wanting to do something similar...


    6/30/08 6:21 PM # Posted By Alex mind

    Very interesting article.
    I Added to my bookmarks.Thank you.


    7/20/08 12:03 PM # Posted By free psp games

    Do you know how can i use this for my site?


    8/1/08 2:23 PM # Posted By Dirk

    added my favorits page. man i know


    Add Comment Subscribe to Comments