Re: Document cloneNode

Why wouldn't this work...

The method cloneNode utilizes three protected methods: shallowClone, to do
the immediate cloning stuff; an overload of cloneNode that accepts an owner
parameter; and a cloneChildren method that clones the children as well as
sets their owners.

So, cloneNode (the original) calls shallowClone, gets the owner from the
clone, then calls cloneChildren with the owner. The cloneChildren method
simply iterates over the children and calls the overloaded cloneNode which,
after shallowClone, sets the specified owner.  The key is that a
shallowClone of a Document node immediately sets the owner to the new
document, and the recursive calls to cloneNode propogate this new owner down
the tree, as the cloning is happening.  No double tree walk, and the
prototype of cloneNode (the one in the spec) does not have to change.

Yes, I know that the spec defines the accessor of the owner of Document to
be NULL, but that does not mean we cannot keep it around anyhow.  Comments?

Tom Otvos
Director of Research, EveryWare Development Inc.
http://www.everyware.com/
"Try not! Do, or do not. There is no 'try'." - Yoda

    -----Original Message-----
    From: keshlam@us.ibm.com <keshlam@us.ibm.com>
    To: www-dom@w3.org <www-dom@w3.org>
    Date: Thursday, October 08, 1998 1:30 PM
    Subject: Re: Document cloneNode


    Yep, it's a choice between setOwnerDoc, or a version of Clone that sets
    ownerDoc as a side effect (which avoids a second tree-walk), or trying
to
    guess what Level 2 might look like and implement some form of
    cloneByContent on all the nodes.

    A dozen of one, six-and-a-half of the other...

    I'll do one of these some time in the next day or two, but I'd love to
have
    a good excuse not to <smile>. It's very much special-case code as far as
    Level 1 is concerned, and I've been trying to keep my code size down
    without sacrificing architecture.
    ______________________________________
    Joe Kesselman  / IBM Research
    Unless stated otherwise, all opinions are solely those of the author.

Received on Thursday, 8 October 1998 18:16:55 UTC