Java XML DOM Print printDOM(Node node, OutputStream out, String encoding)

Here you can find the source of printDOM(Node node, OutputStream out, String encoding)

Description

print DOM

License

Apache License

Declaration

public static void printDOM(Node node, OutputStream out, String encoding)
            throws TransformerException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.OutputStream;

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 org.w3c.dom.Node;

public class Main {
    public static void printDOM(Node node, OutputStream out, String encoding)
            throws TransformerException {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer;/*w  w  w  .  jav a2s .co  m*/
        transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
                "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
        transformer.setOutputProperty(
                "{http://xml.apache.org/xslt}indent-amount", "4");

        transformer.transform(new DOMSource(node), new StreamResult(out));
    }

    public static void printDOM(Node node, OutputStream out) {
        try {
            printDOM(node, out, "UTF-8");
        } catch (TransformerException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. prettyPrintDOM(Node node)
  2. prettyPrintDOM(Node node, OutputStream stream)
  3. prettyPrintDOMAsHTML(Node node, OutputStream stream)
  4. printDom(Node dom, OutputStream os)
  5. printDOM(Node root, OutputStream os)
  6. printDOMTree(Node node, PrintWriter out, String docType, String copyright)
  7. printTreeDOM(final Element samlToken, final boolean isIndent)