Merge two or more XML files into one using XercesC
Posted on 2008-10-16
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.
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.