addNode(tempDocument, tempRootElement, tempRootNode);
tempDocument.appendChild(tempRootElement);
// write the XML Document
File tempFile = new File(inFileName);
OutputFormat format = new OutputFormat( tempDocument ); //Serialize DOM
format.setIndenting(true);
format.setLineSeparator("\n");
FileWriter fout = new FileWriter(tempFile); //Writer will be a String
XMLSerializer serial = new XMLSerializer( fout, format );
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize( tempDocument.getDocumentElement() );
fout.close();