Solved

Merge two or more XML files into one using XercesC

Posted on 2008-10-16
1
685 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

11 Experts available now in Live!

Get 1:1 Help Now