function loadData() {
var xmlData=phoneForm.savedData;
xmlData.load("savedXML");
xmlData.value=xmlData.getAttribute
("persistedData");
//if not the first time, check userData first
if((xmlData.value)!="null") {
data.loadXML(xmlData.value);
}
else {
//then check for the file
var dataFile = "c:\\phone.xml";
var forReading = 1;
var ts, s;
var fso = new ActiveXObject
("Scripting.FileSystemObject");
if(fso.fileExists(dataFile)) {
ts = fso.OpenTextFile(dataFile,forReading);
s = ts.readAll();
alert(s);
xmlData.value = s;
data.loadXML(xmlData.value);
}
else {
// If you made it here, this is the first view
// or there's no locally saved data.
// Do nothing, use the server version
return;
}
}
}
The preceding code is almost a reflection of the save() method. First, the code retrieves a reference to the phoneForm's savedData input field. Next, it retrieves the savedXML file from the UserData cache, retrieves the. persistedAttribute key and assigns its value to the form field's value. When the user first loads the page, or if the user has never saved the data, the persistedAttribute key value is "null" and the page populates the data island with the data from the phone.xml file on the server. If the cache contains data, then the call to the loadXML() method loads the data island with the XML stored in the cache. If the cache does not contain data, the application uses the master data from the server.
To test the application, load the page xmlDataDemoWithSave.html into IE. Add a new record, and then click the Save button. Close IE and then reopen it, navigate to the xmlDataDemoWithSave.html file again and move to the last record. The new record you created will reappear.
While this XML data island application is far from complete, you should have a good handle on how to display and manipulate XML data from within IE5. You can see how saving XML-formatted user data provides far more power and flexibility than using cookies. At the very least, you can see that the XML capabilities of IE5 are both flexible and powerful.