Saving RecordsA More Elegant Approach
IE 5 introduced a persistence framework that allows authors to specify an object to persist data--called userDataon the client using DHTML behaviors. The persistence framework lets you save the state of specified objects on a page. I'll make use of the built-in userData persistence mechanism to save the XML document in a hidden form field of the display.
The userData persistence mechanism requires three things:
- A style sheet rule that applies the behavior
- An object whose data will be saved
Here's the style sheet rule for the sample project:
You specify the element to save by assigning a class attribute just as you would any other CSS rule:
Finally, modify the save() function to write to the userData area on the client:
xmlData.value = data.xml;
The save() function first creates a local variable that references the hidden form field. Next, it assigns the value property of the form field variable to the XMLDocument stored in memoryto the. The setAttribute() call associates the value of the form field with a key ("persistedData" in this case). The last line saves the form field to an XML file called "savedXML.xml" stored in the client's userData area. On Windows 95/98, IE stores user data to:
On Windows NT and 2000, IE stores user data to the user's Documents and Settings folder in the path:
Documents and Settings\username\Application
On all Windows machines, the main UserData folder contains sub-folders that hold all the userData that saved on that machine.
There is one big downsideto the userData mechanism--there's a size limitation on the amount of data that can be stored on the client. The amount of space available varies depending on where the document resides. Microsoft's documentation contains conflicting reportsabout the space available for locally persisted data; some sources report 64K, others, 128K.
My Windows 98 machine running IE 5.0 rejects documents larger than 64KB. The phone.xml file I used is initially 40K, which doesn't leave much room for customization by the user. Simply put, if your XML files are larger than 64KB, you'll have to break them up into smaller pieces and save them separately, save them on the server, or bite the bullet and deal with ActiveX object permissionsbut you won't be able to use the userData cache.