RE: DOM Level 1 Becomes a W3C Recommendation

Arnaud Le Hors wrote,

> But remember that the cost of walking up the hierarchy to
> test whether the inserted node is an ancestor only applies
> when the node is already in the tree. In the case where
> the node is not in the tree, that is when it has no parent,

Not so. Consider,

  Node parent = someDoc.createElement("foo");
  Node child = someDoc.createElement("bar");

  parent.appendChild(child);
  child.appendChild(parent);   // 'parent' is not in tree
                               // so no check needed???

  someDoc.appendChild(parent); // Whoops 'someDoc' has a
                               // cycle.

I think you're confusing the case where the new child
is not in the tree (the common case) with the case
where the parent is not in the tree (very rare). It's
only in the latter that it sort of makes sense to say
that no check is needed. But it doesn't even really
make sense here, because this is just the degenerate
case where a child is being appended to the root node
of a document: naturally the check will be quick here
because, the walk from the root node to the root node
is trivial ;-)

Cheers,


Miles

Received on Friday, 2 October 1998 08:41:29 UTC