xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Dupras <bri...@centera.com>
Subject RE: importNode
Date Thu, 27 Jan 2000 16:07:35 GMT
>     ((org.apache.xerces.dom.DocumentImpl)
> mainDoc).importNode( subDoc,true);

I think you want to change this to:

((org.apache.xerces.dom.DocumentImpl)mainDoc).importNode(subDoc.getDocumentE
lement(),true);

It doesn't make much sense to import the Document Node, but it does make
sense to import the Document's main element.  Remember that the Document
Node is not the same as the top level <element> in the document.

Also, remember that after the import you'll need to appendChild() the node
into the hierarchy.

Brian

> -----Original Message-----
> From: Jan Sundin [mailto:jan@sundin.com]
> Sent: Thursday, January 27, 2000 8:56 AM
> To: general@xml.apache.org
> Subject: importNode
> 
> 
> Hi,
> I'm trying to use importNode() to copy one Document to 
> another. My tries are
> unfortunately unsuccessful. The attached code only generates 
> an exception as
> below.
> 
> Ideas, anybody?
> 
> Jan Sundin
> 
> _____________________
> 
> import java.io.*;
> import org.w3c.dom.*;
> 
> public class test {
> 
>   public test() {
> 
>   }
> 
>   public static void main(String arg[]) {
> 
>     Document mainDoc = new org.apache.xerces.dom.DocumentImpl();
>     Element page = mainDoc.createElement("PAGE");
>     mainDoc.appendChild(page);
> 
> 
>     Document subDoc = new org.apache.xerces.dom.DocumentImpl();
>     Element cont = subDoc.createElement("CONTENT");
>     subDoc.appendChild(cont);
> 
>     ((org.apache.xerces.dom.DocumentImpl)
> ainDoc).importNode( subDoc,true);
>   }
> }
> _____________________
> 
> org.apache.xerces.dom.DOMExceptionImpl: HIERARCHY_REQUEST_ERR
>         at java.lang.Throwable.<init>(Compiled Code)
>         at java.lang.Exception.<init>(Compiled Code)
>         at java.lang.RuntimeException.<init>(Compiled Code)
>         at org.w3c.dom.DOMException.<init>(Compiled Code)
>         at org.apache.xerces.domx.DOMException.<init>(Compiled Code)
>         at 
> org.apache.xerces.dom.DOMExceptionImpl.<init>(Compiled Code)
>         at 
> org.apache.xerces.dom.DocumentImpl.importNode(Compiled Code)
>         at test.main(Compiled Code)
> 

Mime
View raw message