Here you can find the source of printDOM(Node root, OutputStream os)
Parameter | Description |
---|---|
root | root node of the document or document itself |
os | stream to output |
Parameter | Description |
---|---|
TransformerException | an exception |
public static void printDOM(Node root, OutputStream os) throws TransformerException
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.OutputStream; public class Main { private static TransformerFactory trFactory = null; /**/* ww w .j a v a 2s . c o m*/ * Prints DOM to output stream. Uses XSLT identity transform for conversion of DOM to string. * * @param root root node of the document or document itself * @param os stream to output * @throws TransformerException */ public static void printDOM(Node root, OutputStream os) throws TransformerException { identityTransform(root, new StreamResult(os)); } private static void identityTransform(Node root, Result res) throws TransformerException { createTransformerFactory(); Transformer tr = trFactory.newTransformer(); tr.setOutputProperty(OutputKeys.METHOD, "xml"); tr.setOutputProperty(OutputKeys.INDENT, "yes"); tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); tr.transform(new DOMSource(root), res); } private static void createTransformerFactory() { if (trFactory == null) trFactory = TransformerFactory.newInstance(); } }