Solved

Merge two or more XML files into one using XercesC

Posted on 2008-10-16
1
688 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 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, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

16 Experts available now in Live!

Get 1:1 Help Now