Re: Is there a method to copy a node from one document to another

At 3:53 PM 1/12/99, Christophe Ney wrote:
>
>I am using the DOM with java servlets and I couldn't find any method
>to copy a node from one document to another document.
>Thanks for your help

Copying a node from one document to another is quite an operation because
the ownerDocument attribute of a node (or clone of a node) cannot be
changed directly. Inserting a node in another document than it was created
for will raise an exception according to the specification.

You may have to test the type of the node using nodeType, create a new node
of the given type for the other document, fill in the new node with the
values from the old node, then repeat this recursively for its children
before inserting it in the other document.

As far as I can tell from the spec, even use of a documentFragment for
copying portions of a document tree won't save you from this tedious
procedure.

-- Terje <Terje@in-progress.com> | Media Design in*Progress

   Software for Mac Web Professionals at <http://www.in-progress.com>

   * C a s c a d e... a comprehensive Cascading Style Sheets editor
   * WebSlides generates presentations displayed with any browser
   * XPublish - for efficient website publishing with XML
   * Make your Web Site a Social Place with Interaction!

Received on Tuesday, 12 January 1999 20:18:05 UTC