- From: Philippe Le Hegaret <plh@w3.org>
- Date: Tue, 24 Aug 1999 11:26:07 +0200
- To: Daniel Glazman <Daniel.Glazman@der.edf.fr>
- CC: www-dom@w3.org
Daniel Glazman wrote: > > Using DOM1, I can't find a way to "cut" a Node from one > document and "paste" it into another one. All methods are > supposed to raise an exception if I try to do that. There is no way to do this in DOM Level 1. You have to create your own function : Node copyNode(Document dstDoc, Node n) { switch (n.nodeType) { case n.ELEMENT_NODE: newElement = doc.createElement(n.tagName); for (i = 0; i < n.attributes.length; i++) { newElement.setAttributeNode(importNode(n.attributes.item(i))); } for (i = 0; i < n.childNodes.length; i++) { newElement.appendChild(importNode(n.childNodes.item(i))); } return newElement; // and so on ... } } This function already exists in DOM Level 2: http://www.w3.org/TR/WD-DOM-Level-2/level-two-core.html#Level-2-Core-Node-importNode Regards, Philippe.
Received on Tuesday, 24 August 1999 05:25:45 UTC