Link to home
Start Free TrialLog in
Avatar of c095276
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?
Avatar of kamaljeets
kamaljeets

can u give the stack trace of the exception, then it will be easy to help.
-kjs
Avatar of c095276

ASKER

org.w3c.dom.DOMException: DOM005 Wrong document
     at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:393)
     at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:325)
     at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:226)
     at com.wachovia.cmg.ciwt.common.xml.XMLManager.appendNode(XMLManager.java:187)
     at com.wachovia.cmg.ciwt.workflow.upes.UPESManager.createProcessContainerFromXML(UPESManager.java:239)
     at com.wachovia.cmg.ciwt.workflow.upes.UPESMain.main(UPESMain.java:48)
Exception in thread "main"
Avatar of c095276

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);
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c095276

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.
Avatar of girionis
>  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.
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