Comparing two minidom objects

Uche Ogbuji uche at ogbuji.net
Fri Nov 12 17:52:41 EST 2004


skip at pobox.com (Skip Montanaro) wrote in message news:<727daa7e.0411081033.276d5eba at posting.google.com>...
> 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.

http://uche.ogbuji.net/tech/akara/nodes/2004-11-08/domlette-whitespace

Last heading.

Short answer: use c14n (xml.dom.ext.c14n in PyXML), or an XML smart
tree compare function, such as the one that comes with 4Suite.

-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
A hands-on introduction to ISO Schematron -
http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Schematron abstract patterns -
http://www.ibm.com/developerworks/xml/library/x-stron.html
Wrestling HTML (using Python) -
http://www.xml.com/pub/a/2004/09/08/pyxml.html
XML's growing pains - http://www.adtmag.com/article.asp?id=10196
XMLOpen and more XML Hacks -
http://www.ibm.com/developerworks/xml/library/x-think27.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/



More information about the Python-list mailing list