- From: John Cowan <cowan@locke.ccil.org>
- Date: Wed, 09 Sep 1998 15:05:50 -0400
- To: DOM List <www-dom@w3.org>
Stephen R. Savitzky wrote: > It is reasonable to expect that cloneNode will copy _everything_ that it is > meaningful to copy I have no such expectations. > (and it is certainly possible to ensure this for any > particular implementation). Indeed. > One could even write this requirement into the > specification. "*One* can't, perhaps, but *two* can." -- Humpty Dumpty But at any rate, four (the authors of the DOM Core PR) did not. The PR says only: # Returns a duplicate of the node, i.e., serves as a generic copy # constructor for Nodes. The duplicate node has # no parent (parentNode returns null.). # # Cloning an Element copies all attributes and their values, # including those generated by the XML processor to # represent defaulted attributes, but this method does not # copy any text it contains unless it is a deep clone, since # the text is contained in a child Text node. Cloning any # other type of node simply returns a copy of this node. > On the other hand, it is clearly impossible to do this with the createXXX > methods -- that's why cloneNode exists in the first place. I believe cloneNode to be a convenience method. Everything it does can be done with: switch (this.nodeType) { case ELEMENT_NODE: new = this.ownerDocument.createElement(...) new.setAttributes(this.getAttributes) break case TEXT_NODE: new = this.ownerDocument.createText(...) etc. etc. -- John Cowan http://www.ccil.org/~cowan cowan@ccil.org You tollerday donsk? N. You tolkatiff scowegian? Nn. You spigotty anglease? Nnn. You phonio saxo? Nnnn. Clear all so! 'Tis a Jute.... (Finnegans Wake 16.5)
Received on Wednesday, 9 September 1998 15:07:36 UTC