Java XML Document to Stream writeXML(Document document, OutputStream os)

Here you can find the source of writeXML(Document document, OutputStream os)

Description

Saves a given XML document to the given output stream.

License

Open Source License

Declaration

public static void writeXML(Document document, OutputStream os) throws IOException 

Method Source Code

//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 {
    /**/*from w ww .j  av a 2s.  com*/
     * 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());
        }
    }
}

Related

  1. writeXML(Document d, OutputStream out)
  2. writeXML(Document doc, OutputStream os)
  3. writeXML(Document doc, OutputStream os)
  4. writeXML(Document doc, OutputStream out)
  5. writeXml(Document doc, OutputStream outputStream)
  6. writeXML(final Document doc, final OutputStream out)
  7. writeXML(OutputStream os, Document doc)
  8. writeXml(OutputStream outputEntry, Document document)
  9. writeXmlDocumentToStream(Document document, OutputStream stream)