|
Holding the Bag With XML DOM
The XML bag repository stores state information and offers cross-platform compatibility
by Kurt Cagle
Posted May 6, 2003
On occasion, I have found myself sorely in need of a bag. Now, this isn't the paper-or- plastic bag issue that you have to resolve every time you go shopping for groceries. In this particular case, a bag is a repository, a place to store state information temporarily. A bag is similar to a collection in Visual Basic or a hash in most other languages, although in this case, the mechanism I want to use to implement this bag is XML-based. This in turn gives the bag a few capabilities that other storage mechanisms might not have, such as the ability to access the contents of that bag via Xpath.
The idea behind a bag is simple—it holds things, regardless of what those things are. Bags tend to be a pain in traditionally strongly typed languages such as Java, since this inclusiveness requires some fairly fast and fancy playing with object pointers—in essence telling the compiler to look the other way while such information is stored. However, because XML is intrinsically untyped, even in the face of schemas (schemas exist as suggestions about type, not necessarily explicit impositions of type), you can store any kind of information in an XML bag.
For instance, suppose that you wanted to store these pieces of information in a bag: the name of a person (as a string), the date you're planning to meet (as a date), the name of a location where you're planning to meet (another string) and a GPS location (as a complex type). This information could be encoded readily like this:
<bag xmlns:xs="http://www.w3.org/2001/XMLSchema-
datatypes">
<item key="personToMeet">
Aleria Delamare
</item>
<item key="meetingDateTime" type="xs:dateTime">
2003-02-20T10:00:00.000
</item>
<item key="locationName">
Starbucks
</item>
<item key="location" type="GPSPosition"
schemaLocation="http://www.metaphoricalweb.com/
schemas/gpsPosition.xsd">
<gpsPosition>
<latitude>47.7113</latitude>
<longitude>-122.2342</longitude>
</gpsPosition>
</item>
</bag>
Note that this isn't a definitive object—instead, the bag contains information that might be stored between session states, perhaps even user information that varies depending on the requirement of the user (such as CSS properties that need to be changed).
The simplest <item>s within the bag consist of strings and follow the concept of a simple associative array:
<item key="personToMeet">
Aleria Delamare
</item>
Back to top
|