Java XML Document Serialize serialise(Document doc, OutputStream out)

Here you can find the source of serialise(Document doc, OutputStream out)

Description

serialise

License

GNU General Public License

Declaration

public static void serialise(Document doc, OutputStream out)
            throws TransformerException 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 * Version: GPL 2.0//  w w w.  ja va2s  .co m
 *
 * The contents of this file are subject to the GNU General Public
 * License Version 2 or later (the "GPL").
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *   MiniG.org project members
 *
 * ***** END LICENSE BLOCK ***** */

import java.io.OutputStream;

import javax.xml.transform.OutputKeys;
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.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

public class Main {
    public static void serialise(Document doc, OutputStream out)
            throws TransformerException {
        TransformerFactory fac = TransformerFactory.newInstance();
        Transformer tf = fac.newTransformer();
        tf.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
        Source input = new DOMSource(doc.getDocumentElement());
        Result output = new StreamResult(out);
        tf.transform(input, output);
    }
}

Related

  1. serialiseDOM(Document doc, String filepath)
  2. serialize(Document d, File f)
  3. serialize(Document d, OutputStream out, URL transformerLocation, Map properties)
  4. serialize(Document doc)