My requirement is to merge multiple xml files, where each file will be generated in a while loop and the merge the combined xml file to a root xml. I tried to follow below structure, but its not working. Can anyone please suggest is it the right approach. Also I cannot go for any xpath option since the xml which will be created will be dynamic each time...but the namespace will be same.
public Document xmlCreation(){
Document document1 = createDocument();
Node node1 = document1.getDocumentElement(); //Root node
//xml root node created
Document document2 = createDocument();
while(condition)
{
// some steps
Document document3 = createDocument();
Node node3 = document3.getDocumentElement(); //child node
// xml created
node3.appendChild(document2);
}
Node node2 = document2.getDocumentElement();
addChildNode(document1,node2);
return(document1);
}
Thank You in advance !!