Based on examining your code, it appears you copied the final EndElement
from the first file to the output, putting you back at the top level. When you then tried to write the (correct) StartElement
from the second file, you were trying to insert this at root level.
Filter out (i.e. do not write) the EndElement
from the first file.
CLICK HERE to find out more related problems solutions.