Java XML Document to Stream writeDocument(Document document, OutputStream documentOutputStream)

Here you can find the source of writeDocument(Document document, OutputStream documentOutputStream)

Description

Write the DOM Document to specified OutputStream

License

Open Source License

Parameter

Parameter Description
document DOM document
documentOutputStream output stream

Exception

Parameter Description
TransformerFactoryConfigurationError transformer config error
TransformerException transformer error
IOException IO error

Declaration

public static void writeDocument(Document document,
        OutputStream documentOutputStream)
        throws TransformerFactoryConfigurationError,
        TransformerException, IOException 

Method Source Code

//package com.java2s;
/*/*w  ww  .j a  va  2 s .  co m*/
 * eID Identity Provider Project.
 * Copyright (C) 2010 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see
 * http://www.gnu.org/licenses/.
 */

import java.io.IOException;
import java.io.OutputStream;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

public class Main {
    /**
     * Write the DOM {@link Document} to specified {@link OutputStream}
     * 
     * @param document
     *            DOM document
     * @param documentOutputStream
     *            output stream
     * @throws TransformerFactoryConfigurationError
     *             transformer config error
     * @throws TransformerException
     *             transformer error
     * @throws IOException
     *             IO error
     */
    public static void writeDocument(Document document,
            OutputStream documentOutputStream)
            throws TransformerFactoryConfigurationError,
            TransformerException, IOException {
        Result result = new StreamResult(documentOutputStream);
        Transformer xformer = TransformerFactory.newInstance()
                .newTransformer();
        Source source = new DOMSource(document);
        xformer.transform(source, result);
    }
}

Related

  1. write(Document doc, OutputStream out, String enc)
  2. write(Document document, OutputStream byteStream)
  3. writeDocument(Document doc, OutputStream os)
  4. writeDocument(Document doc, OutputStream os)
  5. writeDocument(Document doc, Transformer transformer, OutputStream out)
  6. writeDocument(Document document, OutputStream os)
  7. writeDocument(Document document, OutputStream outputStream)
  8. writeDocument(OutputStream iStream, Element iElement)
  9. writeDocument(OutputStream os, Document document)