Comparing two minidom objects

Andrew Clover and-google at doxdesk.com
Sat Nov 13 12:05:41 EST 2004


Diez B. Roggisch <deetsNOSPAM at web.de> wrote:

> The nodeName is just one property you can check for equality - maybe you
> want to additionally compare nodeType and nodeValue.

Probably. Also each of Element.attributes if there are any attributes
in the object, and Node.namespaceURI if the document uses namespaces.

Skip Montanaro <skip at pobox.com> wrote:

> I'd like to compare two xml.dom.minidom objects, but the naive attempt fails
> >>> d1 == d2
> False

DOM Level 3 Core defines the method Node.isEqualNode:

  http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-isEqualNode

Which would do such a comparison. minidom doesn't support it yet, but
pxdom does. Otherwise, it's not too much work to write a recursive
comparator such as the above.

(The Python == operator does the same as DOM3's Node.isSameNode, or
'is'.)

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Python-list mailing list