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

Re: cloneNode() and insert into another document

From: <keshlam@us.ibm.com>
Date: Wed, 9 Feb 2000 08:57:37 -0500
cc: www-dom@w3.org
Message-ID: <85256880.004CAD13.00@D51MTA03.pok.ibm.com>
FAQ PROPOSAL, since it comes up on a regular basis in every XML-related
discussion I monitor...

Nodes may not be moved directly from one Document to
another. To accomplish this task, you must create new
nodes in the target document, using the data from the
source document.

It's not hard to write a simple tree-walker to do this, but
it's a nuisance. DOM Level 2 will add the importNode()
method to do that work for you. Some DOMs (eg IBM's)
already include a prototype of that function. But if you want
a portable solution that will work with DOM Level 1, you
have to provide your own routine for the purpose.

A better alternative, in many cases, is not to create a second
Document at all. If you can pass your main Document into
whatever routine is generating the second tree, and use its
factories, you'll be able to insert those nodes directly.


For future reference: DOM Level 3 is looking at the general
issue of loading/storing DOMs, and I would expect that the
question of loading additional data into an existing document
is one of the use cases they've considered.

______________________________________
Joe Kesselman  / IBM Research
Received on Wednesday, 9 February 2000 08:58:05 GMT

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