You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by felix <ro...@supercable.es> on 2001/05/31 18:19:37 UTC

exception appending Element to Node

In the next code, this error appears 
"org.w3c.dom.DOMException: DOM005 Wrong document":


......
Node nodeChild=nl.item(0);
DOMParser dp=new DOMParser();
dp.parse(new InputSource(new StringReader("<"+sNameElement+">"+"</"+sNameElement+">")));
Element root=dp.getDocument().getDocumentElement();
root.setAttribute("Order",sOrderElement);
root.setNodeValue(sValueElement);
nodeChild.appendChild(root);
....

I don't know where is the problem, any help would be appreciate

Regards

Re: exception appending Element to Node

Posted by Tom Bradford <br...@dbxmlgroup.com>.
> felix wrote:
> 
> In the next code, this error appears
> "org.w3c.dom.DOMException: DOM005 Wrong document":

Don't forget to import the Node:

Document ownerDoc = // whether nodeChild's owner is
...
nodeChild.appendNode(ownerDoc.importNode(root, true));

-- 
Tom Bradford --- The dbXML Project --- http://www.dbxml.org/
We store your XML data a hell of a lot better than /dev/null

Re: exception appending Element to Node

Posted by Ian Roberts <ir...@decisionsoft.com>.
On Thu, 31 May 2001, felix wrote:

> In the next code, this error appears 
> "org.w3c.dom.DOMException: DOM005 Wrong document":
> 
> 
> ......
> Node nodeChild=nl.item(0);
> DOMParser dp=new DOMParser();
> dp.parse(new InputSource(new StringReader("<"+sNameElement+">"+"</"+sNameElement+">")));
> Element root=dp.getDocument().getDocumentElement();
> root.setAttribute("Order",sOrderElement);
> root.setNodeValue(sValueElement);
> nodeChild.appendChild(root);
> ....
> 
> I don't know where is the problem, any help would be appreciate

You can't do nodeChild.appendChild(root) as the two nodes come from
different Documents.  You need to use the importNode method of the
Document which nodeChild belongs to.  The JavaDocs should tell you the
rest (or look at the list archives - this question is frequently asked).

Ian

-- 
Ian Roberts, Software Engineer        DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org