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 tom john <cy...@yahoo.com> on 2001/12/19 11:56:56 UTC
Adding New Child node to a Document
Hi,
i have xml documents of the same type (same dtd) i
have to get root nodes (including all inner nodes)
from all these xml docs and add it to the new xml
document with different root node.
i get this error when i try to add the first node i
extract:
Exception in thread "main" org.w3c.dom.DOMException:
DOM005 Wrong document
at
org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java
:394)
at
org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:326)
at
org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:224)
at check.main(check.java:72)
the code i am using is:
DocumentImpl newdoc = new DocumentImpl();
Document xmldoc =
Core.XmlCore.file2Document("note.xml");
if(xmldoc != null)
{
Element _node = (Element)xmldoc.getDocumentElement();
Element root =
newdoc.createElement("root");
root.appendChild(_node );
newdoc.appendChild(root);
}
else
System.err.println("null");
hope you can help
regards,
top
__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Adding New Child node to a Document
Posted by Christian Geuer-Pollmann <ge...@nue.et-inf.uni-siegen.de>.
> i have xml documents of the same type (same dtd) i
> have to get root nodes (including all inner nodes)
DTD is not important for that.
> the code i am using is:
>
> DocumentImpl newdoc = new DocumentImpl();
>
> Document xmldoc =
> Core.XmlCore.file2Document("note.xml");
>
> if(xmldoc != null)
> {
> Element _node = (Element)xmldoc.getDocumentElement();
> Element root =
> newdoc.createElement("root");
>
> root.appendChild(_node );
> newdoc.appendChild(root);
> }
boolean deep = true;
Node readyToBeImported = newdoc.importNode(_node, deep);
Element root = newdoc.createElement("root");
root.appendChild(readyToBeImported);
newdoc.appendChild(root);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org