W3C home > Mailing lists > Public > www-dom@w3.org > October to December 1998

Equality tests on DOM nodes

From: Andrew M. Kuchling <akuchlin@cnri.reston.va.us>
Date: Fri, 11 Dec 1998 11:53:02 -0500 (EST)
To: www-dom@w3.org
Cc: xml-sig@python.org
Message-ID: <13937.18858.948855.840376@amarok.cnri.reston.va.us>
[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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:46 GMT