Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Add Persistence to Your XML Data Islands-7 : Page 7


advertisement
Saving Records—A More Elegant Approach
IE 5 introduced a persistence framework that allows authors to specify an object to persist data--called userData—on 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
  • JavaScript functions that write the data to the client machine.
Here's the style sheet rule for the sample project:

<style> .storeUserData { behavior:url(#default#userData); } </style>

You specify the element to save by assigning a class attribute just as you would any other CSS rule:

<input type="hidden" value="null" id="savedData" class="storeUserData"> </input>

Finally, modify the save() function to write to the userData area on the client:



function save(){ //userData implementation var xmlData=phoneForm.savedData; xmlData.value = data.xml; xmlData.setAttribute("persistedData", xmlData.value); xmlData.save("savedXML"); }

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:

C:\WINDOWS\Application Data\Microsoft\Internet Explorer\UserData

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 Data\Microsoft\Internet Explorer\UserData.

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 permissions—but you won't be able to use the userData cache.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date