DOM Node.cloneNode()

Tyler Baker tyler at infinet.com
Tue Aug 18 18:06:57 BST 1998


In the most recent DOM spec the method Node.cloneNode(boolean deep) does
not really specify how the Node should be cloned (e.g. a shallow copy or
a deep copy).  It has a boolean "deep" argument that would imply a true
deep copy, but still this is not totally clear as a true deep copy would
be a copy by value instead of the implicit copy by reference.

In other words, if I have a Node named "A" with two children named "B"
and "C", would you do something like this in Java for A:

public Node cloneNode(boolean deep) {
  Node newNode = new NodeImpl();
  // Do attribute copies here
  if (deep) {
    newNode.appendChild(B);
    newNode.appendChild(C);
  }
  return newNode;
}

or else would you do something like:

public Node cloneNode(boolean deep) {
  Node newNode = new NodeImpl();
  // Do attribute copies here
  if (deep) {
    newNode.appendChild(B.cloneNode(deep));
    newNode.appendChild(C.cloneNode(deep));
  }
  return newNode;
}

Similiarly, what happens with the Attributes of a Node is also not too
clear to me.  Are attributes copied by value or by reference as well?
What happens to the parent attribute?  Should it be copied as well or
should it just have the implicit DocumentFragment reference as its
parent?  What happens to the references to the siblings of a node?

Any help on these issues would be greatly appreciated...

Thanx in advance,

Tyler


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list