You may have arrived at this naively, but the primary feature of your XML design is that it is optimized for searching by date. If your XML document is large, and you do a lot of searching by date (which I suspect is the most common use case in a personal organizer), this is a good thing.
Executing this XPath pattern:
/calendar/year[@value='2008']/month[@value='10']/day[@value='7']/activity
will examine many fewer nodes than will using the pattern you'd need to use with Kev's simpler flattened-out organization:
/calendar/activity[@year='2008' and @month='10' and @day='7']
which basically has to look at every node in the document.
Note, by the way, that I'm assuming that the month
and day
attributes are numeric. This is important because you'll almost certainly want to sort this data at some point, and unless you're going to maintain the sort order in the document (which, I'll admit, an argument can be made for), you'll want those attributes in a form that it's easy to sort them in.
It's also important that you're consistent in how you store numeric data in those attributes. (If you want to sound smart in meetings, you can say that you're establishing canonical representations of your data types.) If you use leading zeroes some times and not others, for instance, none of those XPath patterns will work reliably, because @day='7'
won't match a day
attribute set to "07"
. (You can get around that by converting the attributes to numbers in your XPath using the number()
function, but avoiding the problem in the first place is better.)