Re: cloneNode() and insert into another document

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 UTC