Hey,
Try this to write the file back out as .xml
Firstly add this bit of code just above the DOM parse.
Writer output = null;
output = new BufferedWriter(new FileWriter("docname.xml"));
String newline = System.getProperty("line.separator");
To write to the file you need to add the code below. I haven't had a chance to play with your example yet so you will need to experiment with the placement of this code to make it work correctly.
output.write("whatever text to be printed out");
output.write(newline);
And at the end of the code make sure you add:
Otherwise nothing will be written to the file.
I hope this helps!