W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2000

Re: Copying a node from one doc to another

From: David Brownell <david-b@pacbell.net>
Date: Tue, 14 Mar 2000 12:42:42 -0800
To: Eric Richardson <maxwell@telesoft.com>, DOM <www-dom@w3.org>
Message-id: <016e01bf8df5$d8e12180$0907aace@brownell.org>
> I have a template in one XML doc. I want to retrieve an Element from
> that template and insert it into the another Document I am working on in
> the DOM.

Since you're using Sun's DOM, you should be able to use the

    DocumentEx.changeNodeOwner (Node)

method efficiently get past the DOM "can't move nodes between Documents"

I like that better than the DOM L2 approach of

    Document.importNode (Node)

because (a) it's memory-efficient in the typical single-implementation case,
(b) successful results can't discard subclass-specific per-instance data,
(c) importNode is really just a convenience method, but changeNodeOwner
exposes a capability that couldn't otherwise be accessed.

If you didn't want to mutate the original (template) document then
you will need some sort of clone operation, like L2 importNode.  I've
seen operations speed up substantially (factors of at least two)
when those cloning operations were removed.

- Dave
Received on Tuesday, 14 March 2000 15:43:23 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:06 UTC