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 pa...@hp.com on 2000/06/15 20:16:08 UTC

cloneNode... where am I wrong?

Hi, I'm using Xerces 1.0.3 ( I can't upgrade because I'm working with 
Xalan as well)
I'd like to copy a node from a document to another. So, I use cloneNode 
method.
When I try to add the cloned node to the second document, I get an error :
"org.apache.xerces.dom.DOMExceptionImpl: DOM005 Wrong document"

any idea? Am I missing something?

Here is my simple code :

import java.io.*;
import org.w3c.dom.*;
import org.apache.xerces.parsers.DOMParser;

public class testclone{

  public static void main(String[] args){
    try{
     DOMParser parser=new DOMParser();
     DOMParser parser2=new DOMParser();

     parser.parse("sub.xml");
     parser2.parse("subencr.xml");

     Node doc=parser.getDocument();
     Document doc2=parser2.getDocument();
     Node nde=doc2.getFirstChild();
     Node clone=nde.cloneNode(true);
     doc.appendChild(clone);
    }catch(Exception e)
	{System.out.println(e);
    }
  }
}

Thanks,
Patrick