c095276
asked on
Merging two XML documents
I am using the xerces DOMParser with Java. I want to be able to take the top level node from one document
and append or insert it into a Node on a second, different Document. When I try to simply call appendChild I get an exception that says "Wrong Document". Is there a simply way of doing this?
and append or insert it into a Node on a second, different Document. When I try to simply call appendChild I get an exception that says "Wrong Document". Is there a simply way of doing this?
ASKER
org.w3c.dom.DOMException: DOM005 Wrong document
at org.apache.xerces.dom.Pare ntNode.int ernalInser tBefore(Pa rentNode.j ava:393)
at org.apache.xerces.dom.Pare ntNode.ins ertBefore( ParentNode .java:325)
at org.apache.xerces.dom.Node Impl.appen dChild(Nod eImpl.java :226)
at com.wachovia.cmg.ciwt.comm on.xml.XML Manager.ap pendNode(X MLManager. java:187)
at com.wachovia.cmg.ciwt.work flow.upes. UPESManage r.createPr ocessConta inerFromXM L(UPESMana ger.java:2 39)
at com.wachovia.cmg.ciwt.work flow.upes. UPESMain.m ain(UPESMa in.java:48 )
Exception in thread "main"
at org.apache.xerces.dom.Pare
at org.apache.xerces.dom.Pare
at org.apache.xerces.dom.Node
at com.wachovia.cmg.ciwt.comm
at com.wachovia.cmg.ciwt.work
at com.wachovia.cmg.ciwt.work
Exception in thread "main"
ASKER
Here is a code snippet I have removed all the unnecessary stuff such as exception handling
// missing navigate parent document to correct node set to parentNode
InputSource xmlSource = new InputSource(new StringReader(xmlStr));
DOMParser strParser = new DOMParser();
Document newXMLDoc = strParser.parse(xmlSource) ;
Node nodeToBeInserted = newXMLDoc.getFirstChild();
parentNode.appendChild( nodeToBeInserted);
// missing navigate parent document to correct node set to parentNode
InputSource xmlSource = new InputSource(new StringReader(xmlStr));
DOMParser strParser = new DOMParser();
Document newXMLDoc = strParser.parse(xmlSource)
Node nodeToBeInserted = newXMLDoc.getFirstChild();
parentNode.appendChild( nodeToBeInserted);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What is the type of doc1? I have an object of type org.w3c.dom.Document and I do not have an importNode fucntion.
> I have an object of type org.w3c.dom.Document and I do not have an importNode
fucntion.
Are you sure you are using the latest Java XML APIs?
P.S. I think the moderators should add a "quote" function for replies. It would be quite handy.
fucntion.
Are you sure you are using the latest Java XML APIs?
P.S. I think the moderators should add a "quote" function for replies. It would be quite handy.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- points to heyhey_
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
girionis
Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- points to heyhey_
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
girionis
Cleanup Volunteer
-kjs