private static void write ( Node node , Writer writer , int indentation , boolean omitXmlDeclaration ) { TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; if ( indentation > 0 ) { transformerFactory . setAttribute ( "indent-number" , indentation ) ; } Transformer transformer = null ; try { transformer = transformerFactory . newTransformer ( ) ; } catch ( TransformerConfigurationException canNotHappen ) { // Can not happen here throw new XmlException ( "Could not create transformer" , canNotHappen ) ; } transformer . setOutputProperty ( OutputKeys . STANDALONE , "yes" ) ; transformer . setOutputProperty ( OutputKeys . INDENT , propertyStringFor ( indentation > 0 ) ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , propertyStringFor ( omitXmlDeclaration ) ) ; DOMSource source = new DOMSource ( node ) ; StreamResult xmlOutput = new StreamResult ( writer ) ; try { transformer . transform ( source , xmlOutput ) ; } catch ( TransformerException e ) { throw new XmlException ( "Could not transform node" , e ) ; } }
Writes a formatted String representation of the given XML node to the given writer .