Here you can find the source of writeXML(Document document, OutputStream os)
public static void writeXML(Document document, OutputStream os) throws IOException
//package com.java2s; // This file is part of nzdis-util package. See the file LICENSE for copyright information import java.io.IOException; import java.io.OutputStream; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { /**/*from w ww .j av a 2s. com*/ * Saves a given XML document to the given output stream. */ public static void writeXML(Document document, OutputStream os) throws IOException { DOMSource src = new DOMSource(document); StreamResult res = new StreamResult(os); TransformerFactory tf = TransformerFactory.newInstance(); try { Transformer t = tf.newTransformer(); t.transform(src, res); } catch (TransformerException e) { throw new IOException(e.getMessage()); } } }