Solved

Merge two or more XML files into one using XercesC

Posted on 2008-10-16
1
692 Views
Last Modified: 2008-11-06
I am in a situation where I need to merge two or more XML files into a single xml file. The root node of the first XML will remain the root of merged file. The contents of the other files will appear under the root node and will retain the same structure. To achieve this, I first tried to merge 2 files and faced following problems:

1) Created two DOM Documents. Got the root node of the first document (->GetDocumentElement) and tried to append it to the DOMDocumentFragment of the second document.
Eg: DocumentElement.appendChild(DocumentFrag);

Result: Failed because the owner documents are different

2) Tried adoptNode() to solve owner document issue, but this failed since there is no implementation in xerces.

3) Tried to create DOMNodeList and insert one node at a tiem and even this failed.

4) Observed that DOMBuilder::parseWithContext() might be the possible solution but failed to understand the exact usage from the given documentation.

If you have any work-around or solution to the above problems, please come forward and guide me. Any help will be appreciated.
0
Comment
Question by:Cool-Guy
1 Comment
 

Accepted Solution

by:
Cool-Guy earned 0 total points
ID: 22894692
Got this solution from one  of my colleagues. it may be helpful for others facing the same problem

DOMDocument *DOMTree2 = parser2->getDocument();

DOMNode *newNode2 = DOMTree2->getFirstChild();                  
DOMNode *newNode1 = parser1->getDocument()->importNode(newNode2, true);
DOMTree1->getLastChild()->appendChild(newNode);            
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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