Solved

Merging two XML documents

Posted on 2002-05-15
8
938 Views
Last Modified: 2012-06-21
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?
0
Comment
Question by:c095276
8 Comments
 

Expert Comment

by:kamaljeets
ID: 7010768
can u give the stack trace of the exception, then it will be easy to help.
-kjs
0
 

Author Comment

by:c095276
ID: 7010788
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"
0
 

Author Comment

by:c095276
ID: 7010798
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);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Accepted Solution

by:
heyhey_ earned 200 total points
ID: 7010813
http://www.google.com/search?q=DOM005+Wrong+document&sourceid=opera&num=0&ie=utf-8&oe=utf-8

voids to

http://www-106.ibm.com/developerworks/xml/library/x-tipmvdom.html

which describes solution to your problem

  // Add to first document
            Node newOneToMove = doc1.importNode(oneToMove, true);
            firstRoot.appendChild(newOneToMove);
        } catch (Exception e) {
0
 

Author Comment

by:c095276
ID: 7010834
What is the type of doc1?  I have an object of type org.w3c.dom.Document and I do not have an importNode fucntion.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7010846
>  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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8749725
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now