Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// This file is part of nzdis-util package. See the file LICENSE for copyright information

import java.io.IOException;

import java.io.OutputStream;

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;

public class Main {
    /**
     * Saves a given XML document to the given output stream.
     */
    public static void writeXML(Document document, OutputStream os) throws IOException {
        DOMSource src = new DOMSource(document);
        StreamResult res = new StreamResult(os);
        TransformerFactory tf = TransformerFactory.newInstance();
        try {
            Transformer t = tf.newTransformer();
            t.transform(src, res);
        } catch (TransformerException e) {
            throw new IOException(e.getMessage());
        }
    }
}