Here you can find the source of writeXml(OutputStream os, Node node, String encoding)
public static void writeXml(OutputStream os, Node node, String encoding) throws TransformerException
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import javax.xml.transform.OutputKeys; 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 java.io.*; public class Main { public static void writeXml(OutputStream os, Node node, String encoding) throws TransformerException { TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty("indent", "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, encoding); DOMSource source = new DOMSource(); source.setNode(node);// www. jav a 2s . c o m StreamResult result = new StreamResult(); result.setOutputStream(os); transformer.transform(source, result); } }