Here you can find the source of print(Element elm, OutputStream out)
Parameter | Description |
---|---|
elm | Root element which should be written |
out | OuputStream |
Parameter | Description |
---|---|
TransformerException | an exception |
public static void print(Element elm, OutputStream out) throws TransformerException
//package com.java2s; //License from project: Open Source License import java.io.OutputStream; import java.io.Writer; 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; import org.w3c.dom.Element; public class Main { /**/* ww w . j a v a2 s.co m*/ * Serialize W3C document into given output stream * @param doc W3C document * @param out OutputStream * @throws TransformerException */ public static void print(Document doc, OutputStream out) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(out); transformer.transform(source, result); } /** * Print document to given writer * @param doc Printing document * @param out Writer * @throws TransformerException */ public static void print(Document doc, Writer out) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(out); transformer.transform(source, result); } /** * Print part of document * @param elm Root element which should be written * @param out OuputStream * @throws TransformerException */ public static void print(Element elm, OutputStream out) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(elm); StreamResult result = new StreamResult(out); transformer.transform(source, result); } /** * Print part of document * @param elm Root element which should be written * @param out Writer * @throws TransformerException */ public static void print(Element elm, Writer out) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(elm); StreamResult result = new StreamResult(out); transformer.transform(source, result); } }