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

Re: Cut/Paste from one document to another

From: Philippe Le Hegaret <plh@w3.org>
Date: Tue, 24 Aug 1999 11:26:07 +0200
Message-ID: <37C2652F.3A0DBA5B@w3.org>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:46 GMT