Java XML Document to Stream write(Document document, OutputStream byteStream)

Here you can find the source of write(Document document, OutputStream byteStream)

Description

Writes the given document to the given output stream.

License

Open Source License

Parameter

Parameter Description
document A DOM document.
byteStream The OutputStream to write to.

Declaration

public static void write(Document document, OutputStream byteStream) 

Method Source Code


//package com.java2s;

import java.io.OutputStream;

import org.w3c.dom.Document;

import org.w3c.dom.ls.DOMImplementationLS;

import org.w3c.dom.ls.LSOutput;

import org.w3c.dom.ls.LSSerializer;

public class Main {
    /**//from w  w  w .  ja va 2s.co  m
     * Writes the given document to the given output stream.
     * 
     * @param document
     *            A DOM document.
     * @param byteStream
     *            The {@link OutputStream} to write to.
     */
    public static void write(Document document, OutputStream byteStream) {
        DOMImplementationLS impl = (DOMImplementationLS) document.getImplementation();

        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteStream);

        LSSerializer serializer = impl.createLSSerializer();
        serializer.getDomConfig().setParameter("format-pretty-print", true);
        serializer.write(document, output);
    }
}

Related

  1. dom2InputStream(Document doc)
  2. dumpDoc(Document domTree, PrintStream out)
  3. dumpToStream(Document doc, OutputStream out)
  4. toXml(Document doc, OutputStream out)
  5. write(Document doc, OutputStream out, String enc)
  6. writeDocument(Document doc, OutputStream os)
  7. writeDocument(Document doc, OutputStream os)
  8. writeDocument(Document doc, Transformer transformer, OutputStream out)
  9. writeDocument(Document document, OutputStream documentOutputStream)