RE: Equality tests on DOM nodes

Not to sound facetious, but to put this question in context, I might well
ask how we implement < and > for nodes?  We generally don't use those
particular operators on something real.  I would never say rock a > rock b,
but I might say rock a weighs more than rock b.  With respect to the
equality and equivalence, I am very safe saying book a has the same author
as book b, because she's really the same person.  If I'm talking about book
a and someone else is talking about book b, I might point out that they are
talking about the same book.  But if I say book a is the same as book b for
two different books, while this is a commonly used construct, it invites
argument --- "No, this book is dog-eared and has coffee stains on it.  I
want *my* book back!"

"Honey, these two coffee tables are identical.  Let's get the cheaper one."
"No.  This one is particle board and veneer, while this one is mission oak!
How can you think they're the same?"

What was my point?  I think it was to say that it invites folly, especially
when you're talking about an international, world-wide, universal standard,
to specify that two things are equal when they do not refer to the same
thing and/or measurable differences exist between them.  It seems obvious
 perhaps only to me ) that attributes must be equal and the equality must be
true recursively, if you dare to define equality for nodes.  I think the
next question might be,

Does context make a difference in equality or equivalence?

I could easily say that this paragraph is identical to that paragraph when
we're talking about a printed page, but XML, in it's most commonly discussed
usage, is about document metadata, and context is a part of that metadata.
A node is, after all, part of a larger document.

Paul

-----Original Message-----
From: www-dom-request@w3.org [mailto:www-dom-request@w3.org]On Behalf Of
Andrew M. Kuchling
Sent: Friday, December 11, 1998 11:53 AM
To: www-dom@w3.org
Cc: xml-sig@python.org
Subject: 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 12:58:06 UTC