Re: [xmljs-users] Comparing two DOMDocuments for equality?
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2004-10-25 04:04:01
|
Hi Stepan! There isn't any way currently to do what you're doing, but my suggestion would be to do exactly what you're proposing. I think you're on the right track. Good luck! David --- Stepan Riha <xm...@no...> wrote: > Is there an easy way to compare the contents of two W3C DOMDocument objects for > equality? Right now I try to do this by comparing (doc1.toString() == > doc2.toString()), but that may return false if the order in which attributes > were added to nodes in the documents is different (even though the documents > are semantically equivalent). It would be nice if there was a compare() method > I could call on the DOMDocument or if the toString() methods would produce a > canonical form. > > I'm planning to implement the canonical toString() by changing the > DOMNamedNodeMap_toString() method to concatenate the elements sorted by their > names. This should produce the same value regardless of the order in which > elements were added to the NamedNodeMap. > > The reason I'm doing this is that in my XML editing web app, I want to warn a > user if they leave the page without having saved the changes they made. So on > page load, I capture the current XML document and in my window.onbeforeunload > handler I compare it with the current (edited) document, and if they differ, > display a warning. With the current implementation I sometimes get a warning > if the user just "clicks around" because I delete/reinsert attributes in a > different order. > > - Stepan > > -- > Stepan Riha > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users > |