In Java:
Suppose I have 3 xml files
<student>lin</student> -- file1.xml
<student>Eric</student> -- file2.xml
<student>joe</student> -- file3.xml
How can I merge these xml’s (considering that they don’t have the DTD or namespace declaration) to create
<class><student>lin</student> <student>Eric</student>
<student>joe</student> </class> -- file4.xml
class being the wrapping node I supply manually
Ps: I used xstream to create the xml’s
I your files are large I would use a SAXParser where your ContentHandler would echo the tags and the content.
Something like (pseudo-code):
If your files are small enough to fit into the memory: load the DOM of each document using a DocumentBuilder and call importNode to merge the documents into one.