Re: Copying from one DOM to another

>1) I don't understand why a document has to own all nodes it can
>reference.

Brief answer: Because that's what the spec says.

Longer answer: Because implementing a DOM often involves nonpublic
interfaces (in order to achieve the desired behavior), and those won't work
across implementations. And because Documents may be subclassed
differently, in some DOMs, which can further impede interchangability of
nodes.

>2) If I get a reference to DOM document, what should I do to be certain
>that the changes I do, don't reflects in the original data structure?
>Should I use importNode (to a memory-only document) or cloneNode?

I'm not sure what question you're asking. If you don't want to affect the
original DOM tree, don't alter the nodes which belong to that tree -- copy
them first. Whether that should be done via cloneNode or by importing into
a new Document is up to you, and depends on what you intend to do with the
copied nodes.


______________________________________
Joe Kesselman  / IBM Research

Received on Saturday, 18 November 2000 11:49:02 UTC