try {
// lets write to a file
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setTrimText( false );
XMLWriter writer = new XMLWriter(
new FileWriter( new File( reportDirectory, fileName ) ), outformat
);
writer.write( document );
writer.close();
} catch ( IOException e ) {
throw new RuntimeException( e );
}