Here you can find the source of toStream(Document document, OutputStream stream)
Parameter | Description |
---|---|
document | The XML document to persist. |
stream | The stream to write into. |
Parameter | Description |
---|---|
TransformerException | an exception |
TransformerConfigurationException | an exception |
public static void toStream(Document document, OutputStream stream) throws TransformerException, TransformerConfigurationException
//package com.java2s; //License from project: Open Source License import java.io.OutputStream; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.*; public class Main { /**// w w w .ja v a 2s . com * Saves an XML Document into a stream. * * @param document * The XML document to persist. * @param stream * The stream to write into. * @throws TransformerException * @throws TransformerConfigurationException */ public static void toStream(Document document, OutputStream stream) throws TransformerException, TransformerConfigurationException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); Source input = new DOMSource(document); Result output = new StreamResult(stream); transformer.transform(input, output); } }