W3C home > Mailing lists > Public > www-dom@w3.org > July to September 1998

Re: Should Document.cloneNode() work in Level 1?

From: Stephen R. Savitzky <steve@crc.ricoh.com>
Date: 08 Sep 1998 13:37:11 -0700
To: "Don Park" <donpark@quake.net>
Cc: <www-dom@w3.org>
Message-ID: <qcaf4a9w94.fsf@gelion.crc.ricoh.com>
"Don Park" <donpark@quake.net> writes:

> >A better alternative would be to put this on Document rather than Node:
> >
> >  Node cloneNode(Node original, boolean deep)
> All nice and dandy except for the weird look code:

On second thought, it should be called something different, like createCopy.
> Document doc = node.getOwnerDocument();
> doc.cloneNode(node, doc);

newDoc.createCopy(node, false); // for a shallow copy
newDoc.createCopy(node, true); // for a deep copy

> It just does not look as natural as:
> Node newNode = oldNode.cloneNode(true, null); // for same doc
> Node newNode = oldNode.cloneNode(true, someOtherDoc);

We should keep the existing Node method cloneNode, with no added document
parameter.  That way if you want to add a duplicate node to the same
document you use cloneNode; if you want to creat a copy in another document
you use createCopy. 

newParent.appendChild(newParent.getOwnerDocument().copyNode(oldNode, true));

(as opposed to:
 newParent.appendChild(oldNode.cloneNode(true, newParent.getOwnerDocument()));
 under the other proposal.)

My way looks more natural if you're doing a mixture of node copying and node
creation.  You get the owner document once and perform a series of create

Something like this is really essential if you're in a system (like the one
I'm building) which permits different DOM implementations for different

 Stephen R. Savitzky   Chief Software Scientist, Ricoh Silicon Valley, Inc., 
<steve@rsv.ricoh.com>                            California Research Center
 voice: 650.496.5710   fax: 650.854.8740    URL: http://rsv.ricoh.com/~steve/
  home: <steve@starport.com> URL: http://www.starport.com/people/steve/
Received on Tuesday, 8 September 1998 16:30:51 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:04 UTC