Example usage for javax.xml.transform.dom DOMSource DOMSource

List of usage examples for javax.xml.transform.dom DOMSource DOMSource

Introduction

In this page you can find the example usage for javax.xml.transform.dom DOMSource DOMSource.

Prototype

public DOMSource() 

Source Link

Document

Zero-argument default constructor.

Usage

From source file:Main.java

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);/*  w w  w. j a v a2s  .c  om*/
    StreamResult result = new StreamResult();
    result.setOutputStream(os);

    transformer.transform(source, result);
}