Solved

Merging two XML documents

Posted on 2002-05-15
8
968 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

691 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