Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Deleting Records
Once again, using ADO to delete records is easier than writing the same functionality using the DOM. Add the following code to xmlSave.js:

function deleteRecord(){ //ADO Implementation data.recordset.Delete(); if(data.recordset.absoluteposition<0){ //if you deleted the last record, //move to the "new" last record last(); } else //do nothing, IE will move to the next record return; }

That's it! The Delete() method deletes the current record and,if you are not on the last record, moves on to the next record. If you delete the last record, the record set pointer is moved to the "new" last record. The DOM implementation doesn't offer any great benefit over the ADO implementation but, in the interest of completeness, I offer it here. Modify the deleteRecord() function as follows:

function deleteRecord(){ //DOM Implementation var delRecord = data.XMLDocument.documentElement. childNodes(currentRecord); data.XMLDocument.documentElement. removeChild(delRecord); if(data.recordset.absoluteposition<0){ //if you deleted the last record, //move to the "new" last record last(); } else //do nothing, IE will move to the next record return; }

The DOM implementation stores the current node in a local variable, then deletes the node from the data tree. It's only one more line of code so choosing a method to delete records is largely a matter of taste.

Persisting Data
Saving the updated XML data tree is absolutely necessary in any real world application. In all honesty, when I first began writing this article, I couldn't conceive of any reason to save an application like this on the client. Saving the data to each individual client would result in different versions of the phone book on each machine. Then, a few weeks ago, I received the latest edition of my local phone book from the phone company. It dawned on me that everyone gets the latest snapshot of the phone book that we are free to customize by writing in the margins etc. Saving the XML data to the client mirrors this process.

The data island component exposes an XML property that returns the XML string that makes up the data island. I'll make use of this property to grab the contents of the XMLDocument and persist the data in a couple of ways, each of which has its own limitations.

Comment and Contribute






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



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