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

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

Description

writeDocument streams out given document to given output stream

License

Educational Community License

Parameter

Parameter Description
document a parameter
os a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static void writeDocument(Document document, OutputStream os)
        throws Exception 

Method Source Code

//package com.java2s;
/**// ww w.  j  ava2 s  .  c o  m
 *  This document is a part of the source code and related artifacts
 *  for CollectionSpace, an open source collections management system
 *  for museums and related institutions:

 *  http://www.collectionspace.org
 *  http://wiki.collectionspace.org

 *  Copyright 2009 University of California at Berkeley

 *  Licensed under the Educational Community License (ECL), Version 2.0.
 *  You may not use this file except in compliance with this License.

 *  You may obtain a copy of the ECL 2.0 License at

 *  https://source.collectionspace.org/collection-space/LICENSE.txt

 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.OutputStream;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;

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 {
    /**
     * writeDocument streams out given document to given output stream
     * 
     * @param document
     * @param os
     * @throws Exception
     */
    public static void writeDocument(Document document, OutputStream os)
            throws Exception {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);
    }
}

Related

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