Equality tests on DOM nodes

[CC'ed to xml-sig@python.org and www-dom@w3.org; followups to
 www-dom@w3.org]

With reference to the Python DOM implementation, someone has raised
the question of testing the equality of nodes.  I don't think there's
anything in the DOM Recommendation that discusses this question,
possibly because the issue doesn't raise its head in Java.

	Briefly, what should 'node1 == node2' do?  In Python, object
identity is tested using the 'is' operator, so 'node1 is node2'
returns true iff node1 and node2 are actually the same object.  'node1
== node2' should therefore test for equal values of the node.  This
differs from Java, where n1==n2 tests object identity, and a further
comparison would have to be implemented as a method.

	It seems fairly obvious that node1==node2 should check whether 
the node type and value are identical, and return false if they're
not.  But there are some trickier questions:

	* Should Element instances also compare their attributes?  
I would say 'yes', since the attributes are really associated with the 
Element node.

	* If the two nodes have identical type and value, should the
comparison be recursive, comparing the children of the nodes.  The ==
operator would then be comparing entire subtrees rooted at node1 and
node2.  I'm not certain if this is the best choice for the meaning of
==, but see no clear reason to choose recursive vs. non-recursive ==.
Any suggestions?

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
    Q. Does Kibo believe in furniture?
    A. No. Go away, furniture!
    -- The alt.religion.kibology FAQ

Received on Friday, 11 December 1998 11:53:07 UTC