Re: Equality tests on DOM nodes

Regarding the problem of comparing DOM nodes,
one implementation solution is to assign a "DOM node identifier" (DNI)
to each DOM node, and use these as the basis for comparison.

A DNI is an integer, base 1, which monotonically increases up to the
maximum number of nodes in a particular DOM.
The root node DNI is assigned "1", and the remainder are assigned
in pre-order.

When nodes persist their DNI's persist with them, for any given
version of the particular DOM instance.

So:  how may any two DOM nodes be compared?

Just examine their respective DNI's numerically.

E.g.. a DOM node with DNI 42 is "==" to a DOM node with DNI 42.

DNI_42 > DNI_5

DNI_9 < DNI_12

Of course, this works best for read-only DOM's;
because arbitrary node insertion would disrupt the DNI sequencing.
But I would argue that node insertion results in a new document version
which necessarily has its own uniques set of DNI's anyway.

How's that?

-rll

Received on Friday, 11 December 1998 16:49:39 UTC