I have data that looks like this:
<Stats>
...
<Hits yyyy="2004" mm="02" dd="19" hh="00">
<FL>76</FL>
<HP>24</HP>
<EVNF>27</EVNF>
<EVS>53</EVS>
</Hits>
<Hits yyyy="2004" mm="02" dd="19" hh="01">
<FL>75</FL>
<HP>8</HP>
<CSINF>21</CSINF>
<CSIS>44</CSIS>
<EVNF>7</EVNF>
<EVS>21</EVS>
</Hits>
...
</Stats>
The <Hits /> node covers several months worth of data and will continue to grow. I need to be able to select a range of data within the document so I do the following:
XPathDocument doc = new XPathDocument(Server.MapPath("WebStats.xml"));
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator hits = nav.Select("//Hits[concat(@yyyy, @mm, @dd, @hh) >= '" + fromTimestamp + "' and concat(@yyyy, @mm, @dd, @hh) <= '" + thruTimestamp + "']");
Where fromTimestamp and thruTimestamp are values passed in from an aspx page. This works great to get the appropriate <Hits /> for the range that I need. However, I would like to be able to then perform additional "subqueries" on those results. For instance, I want to be able to get the totals (sum) of the various nodes under <Hits />. I know I could switch to using the Evaluate() method and have something along the lines of:
int aaHits = nav.Evaluate("sum(//Hits[concat(@yyyy, @mm, @dd, @hh) >= '" + fromTimestamp + "' and concat(@yyyy, @mm, @dd, @hh) <= '" + thruTimestamp + "']/AA)");
But to do that seems somewhat inefficient having to query the entire document every time for 6 - 8 different sub nodes. In addition, I place the hits object in cache because it is used from a handler that creates chart images based on the data. So ideally I'd like to select the nodes of the date range I need and avoid having to duplicate the logic for filtering in yet another page. I wouldn't mind duplicating the sub-query on another page since it should be simpler.
Thanks in advance for any assistance.
Matt
Matt Smith
Chief Swoof at swoofware.com