Comparing two minidom objects

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Sat Nov 13 17:22:30 EST 2004


On 8 Nov 2004 10:33:24 -0800, rumours say that skip at pobox.com (Skip
Montanaro) might have written:

>I'd like to compare two xml.dom.minidom objects, but the naive attempt fails:
>
>>>> import xml.dom.minidom
>>>> d1 = xml.dom.minidom.parse("ES.xml")
>>>> d2 = xml.dom.minidom.parse("ES.xml")
>>>> d1 == d2
>False
>
>My goal is to decide whether or not I need to prompt the user to save config
>information at the end of a program run by generating a minidom object then
>comparing it with the last saved version.

Convert your minidom objects into sets of ("key", "value") tuples, where
"key" represents the full path to the key starting from the root
element.  I assume that both "key" and "value" will or can be hashable.
Compare the two sets.
-- 
TZOTZIOY, I speak England very best,
"Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek



More information about the Python-list mailing list