Here you can find the source of serialise(Document doc, OutputStream out)
public static void serialise(Document doc, OutputStream out) throws TransformerException
//package com.java2s; /* ***** BEGIN LICENSE BLOCK ***** * Version: GPL 2.0// w w w. ja va2s .co m * * The contents of this file are subject to the GNU General Public * License Version 2 or later (the "GPL"). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Initial Developer of the Original Code is * MiniG.org project members * * ***** END LICENSE BLOCK ***** */ import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 { public static void serialise(Document doc, OutputStream out) throws TransformerException { TransformerFactory fac = TransformerFactory.newInstance(); Transformer tf = fac.newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ Source input = new DOMSource(doc.getDocumentElement()); Result output = new StreamResult(out); tf.transform(input, output); } }