code: private void writeDocument( Document document, File file )
          throws TransformerException, FileNotFoundException
      {
          document.normalize();
          DOMSource source = new DOMSource( document );
          StreamResult result = new StreamResult( new FileOutputStream( file ) );
          Transformer transformer = TransformerFactory.newInstance().newTransformer();
          transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
          transformer.transform( source, result );
      }
docs: write document to the file
  
  @param document
  @param file
  @throws TransformerException
  @throws FileNotFoundException