Solved

Merge two or more XML files into one using XercesC

Posted on 2008-10-16
1
705 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
[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
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

Independent Software Vendors: 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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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