To date, in our series on Surfing Stats, we have covered the intent, directory structure and the main application file.
(download the code using the download link at the bottom of the the Intro to Surfing Stats post). Now we will look at the datasets.
Surfing Stats consumes XML data representing popular stats categories from BlogCFC. If you look at The nodans.com Stats page, you see many sections of stats. I wrote a quick mod that returns the data in XML form. I also normalized the data member names. You can see the raw data by clicking any of the categories below.
BlogTotals | CategoryCount | CommentedEntries | CommentedCategories | SearchTerms | Commenters |
Here is a sample of the data. This is the commented categories dataset.
We use this data to drive the table and charts in our application.
Requesting XML Data
Requesting XML data in Flex is easy.
private function xmlDataHandler(event:ResultEvent):void
{
//the XML is Converted to an Array Collection by the result event
selectedDatasetAC = event.result.query.row;
//Define, configure amd run a numeric sort
var sort:Sort = new Sort();
sort.fields = [new SortField("amount", false, false, true)];
selectedDatasetAC.sort = sort;
selectedDatasetAC.refresh();
}
The bulk of the code above is for creating a numeric sort and sorting the data. The true magic happens transparently. If you have ever parsed XML, you know that it isn’t hard to walk down an XML tree and populate an object, it is just tedious. If you are a poor typer, like I am, it is also error prone.
Parsing the XML and Populating the ArrayCollection
In the Flex framework, the HTTPService makes the request to the server and then fires a result. The result automatically transforms the XML data into an ArrayCollection. Yay for Us! No boilerplate parsing or external libraries needed! The code above references event.result.query.row, row is the name of the repeatable node in our XML data.
Now that you have a good feel for the data that drives Surfing Stats, we can examine the application mode in depth. In the next series, we will dig into the main application file and look at the layout containers.