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 Is...@DataBeam.com on 2000/04/25 23:22:45 UTC

How do I create a DOM object from a node in another DOM object ?


Hi all,
     I want to create a DOM object from a Node in another DOM object. I can
already guarantee that the Node will be a valid XML document, I just need
to know the syntax to get this to work.

I want to do something like this:

Document original_doc = (DOMParser)parser.getDocument();

Document new_doc = new DocumentImpl();

new_doc.appendChild(original_doc.getDocumentElement().getChildNodes().item(
1));

This should create a new DOM object from a node in the original DOM object,
but it just gives me an error:
"org.apache.xerces.dom.DOMExceptionImpl: DOM005 Wrong Document"

Can anyone help me with this ?

-Isaac



Re: How do I create a DOM object from a node in another DOM object ?

Posted by Bill Sofko <bs...@contrariwise.com>.
Try...

new_doc.appendChild(new_doc.importNode(original_doc.getDocumentElement().getChildNodes().item(1), true));

- Bill

Isaac_Hands@DataBeam.com wrote:
> 
> Hi all,
>      I want to create a DOM object from a Node in another DOM object. I can
> already guarantee that the Node will be a valid XML document, I just need
> to know the syntax to get this to work.
> 
> I want to do something like this:
> 
> Document original_doc = (DOMParser)parser.getDocument();
> 
> Document new_doc = new DocumentImpl();
> 
> new_doc.appendChild(original_doc.getDocumentElement().getChildNodes().item(
> 1));
> 
> This should create a new DOM object from a node in the original DOM object,
> but it just gives me an error:
> "org.apache.xerces.dom.DOMExceptionImpl: DOM005 Wrong Document"
> 
> Can anyone help me with this ?
> 
> -Isaac
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

-- 
Bill Sofko
Publisher, Contrariwise