 <p>When you modify the dom tree, you modify it in memory, but the original file where this dom tree comes from is not affected. You need to write the modified dom tree to the file in order to persist the changes you have made in memory. </p> <p>It's exactly the same as if you read a whole file in a StringBuilder. Modifying the StringBuilder won't magically write the new content to the file.</p> <p>See <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html</a> for example code to write a DOM tree to a file.</p>