Here you can find the source of writeXML(OutputStream os, Document doc)
public static void writeXML(OutputStream os, Document doc) throws TransformerException
//package com.java2s; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.dom.DOMSource; import org.w3c.dom.*; public class Main { /** Factory for generating transformers. */ public static final TransformerFactory TRANS_FACT = TransformerFactory.newInstance(); /** Writes the specified DOM to the given output stream. */ public static void writeXML(OutputStream os, Document doc) throws TransformerException { Transformer idTransform = TRANS_FACT.newTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(os); idTransform.transform(input, output); }/*from w w w .j a va 2 s. c o m*/ }