You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Anouk Udressy <ud...@freesurf.ch> on 2000/08/31 20:59:06 UTC

Copy Element

Hi,

I would like to copy several Elements from a Document Object and put these
Elements in an other Document object. When I try to append an Element from
the initial Document to the aim Document the program throw an exception.
What is the best method for do that ?

Thanks in advance,

A. Udressy



Re: Copy Element

Posted by Arnaud Le Hors <le...@us.ibm.com>.
Carlos Piqueres Ayela wrote:
> 
> It depends...
> 
> It depends on what version of xerces you have.
>
> Xerces 101 adopts DOM Level 1 while Xerces 113 adopts DOM Level2.
> There are subtle changes between both specifications... some of them refer to
> the way of importing information from one tree to another.

I don't know where you got that from but this isn't correct.

> /* in xerces 113 */
> Node clon = form.cloneNode(true);
> // this is a standard method. So docImpl is a reference of DocumentImpl class
> docImpl.adoptNode(clon);

adoptNode is non std, even though it's been submitted to W3C (by me) for
standardization as part of DOM Level 3 (which was just published by the
way! See http://www.w3.org/TR/DOM-Level-3-Core), and it is meant to
*move* nodes from one document to another.
I really don't see why you would use that if what you want is to *copy*
from one document to another. importNode is already part of the std DOM
API and is all you need in that case. So the following is really what
you want to do, regardless of the version of xerces!

> /* in xerces 101 */
> Node clon = docImpl.importNode((Node)item,true);
> doc.getDocumentElement().appendChild(clon);
-- 
Arnaud  Le Hors - IBM Cupertino, XML Technology Group

Re: Copy Element

Posted by Carlos Piqueres Ayela <cp...@tissat.es>.
It depends...

It depends on what version of xerces you have.

Xerces 101 adopts DOM Level 1 while Xerces 113 adopts DOM Level2.
There are subtle changes between both specifications... some of them refer to
the way of importing information from one tree to another.


/* in xerces 113 */
Node clon = form.cloneNode(true);
// this is a standard method. So docImpl is a reference of DocumentImpl class
docImpl.adoptNode(clon);

/* in xerces 101 */
Node clon = docImpl.importNode((Node)item,true);
doc.getDocumentElement().appendChild(clon);


That stuff works with me. I asked the same question several days ago and
someone gave me the keys about that...
Carlos.