public static boolean writeDocumentToFile ( Document doc , String localFile ) { try { TransformerFactory transfact = TransformerFactory . newInstance ( ) ; Transformer trans = transfact . newTransformer ( ) ; trans . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , YES ) ; trans . setOutputProperty ( OutputKeys . INDENT , YES ) ; trans . transform ( new DOMSource ( doc ) , new StreamResult ( new File ( localFile ) ) ) ; return true ; } catch ( TransformerConfigurationException ex ) { LOG . warn ( ERROR_WRITING , localFile , ex ) ; return false ; } catch ( TransformerException ex ) { LOG . warn ( ERROR_WRITING , localFile , ex ) ; return false ; } }
Write the Document out to a file using nice formatting