public static void writeDocument(Document document,String encoding,OutputStream out,Writer writer,boolean omitXMLDeclaration) throws IOException, XMLException {
  if (writer == null) {
    writer=new OutputStreamWriter(out,encoding);
  }
  transformer.setOutputProperty(OutputKeys.ENCODING,encoding);
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,omitXMLDeclaration ? "yes" : "no");
  Source source=new DOMSource(document);
  Result result=new StreamResult(writer);
  try {
    transformer.transform(source,result);
  }
 catch (  TransformerException e) {
    e.printStackTrace();
    throw new XMLException("writeDocument failed",e);
  }
  writer.flush();
}

public static void writeDocument ( Document document , String encoding , OutputStream out , Writer writer , boolean omitXMLDeclaration ) throws IOException , XMLException { if ( writer == null ) { writer = new OutputStreamWriter ( out , encoding ) ; } transformer . setOutputProperty ( OutputKeys . ENCODING , encoding ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , omitXMLDeclaration ? "yes" : "no" ) ; Source source = new DOMSource ( document ) ; Result result = new StreamResult ( writer ) ; try { transformer . transform ( source , result ) ; } catch ( TransformerException e ) { e . printStackTrace ( ) ; throw new XMLException ( "writeDocument failed" , e ) ; } writer . flush ( ) ; }
writes the xml representation of a document object .
