Java XML Document Save to File saveXML(Document doc, ByteArrayOutputStream outputStreamXML)

Here you can find the source of saveXML(Document doc, ByteArrayOutputStream outputStreamXML)

Description

Serializa un XML a ByteArrayOutputStream

License

Open Source License

Parameter

Parameter Description
doc a parameter
outputStreamXML a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static void saveXML(Document doc,
        ByteArrayOutputStream outputStreamXML) throws Exception 

Method Source Code

//package com.java2s;
/**//from  w w  w. ja v a 2 s .  c o  m
 *
 * API XBRL-PGC2007 is a set of packages for the treatment of instances XBRL
 * (eXtensible Business Reporting Language) corresponding to the taxonomy PGC2007.
 * The General Plan of Accounting 2007 is the legal text that regulates the accounting of
 * the companies in Spain.
 *
 * This program is part of the API XBRL-PGC2007.
 *
 * Copyright (C) 2009  INTECO (Instituto Nacional de Tecnolog?as de la
 * Comunicaci?n, S.A.)
 *
 * Authors: Members of Software Quality Department inside INTECO
 *
 * E-mail: difusioncalidad@inteco.es
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software Foundation; 
 * either version 3 of the License, or (at your opinion) any later version.
 *
 * This program 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 program. If not, see http://www.gnu.org/licenses/
 */

import java.io.ByteArrayOutputStream;

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    /**
     * Serializa un XML a ByteArrayOutputStream
     * @param doc
     * @param outputStreamXML
     * @throws Exception
     */
    public static void saveXML(Document doc,
            ByteArrayOutputStream outputStreamXML) throws Exception {

        System.setProperty(DOMImplementationRegistry.PROPERTY,
                "org.apache.xerces.dom.DOMImplementationSourceImpl");
        DOMImplementationRegistry registry = DOMImplementationRegistry
                .newInstance();
        DOMImplementation domImpl = registry.getDOMImplementation("LS 3.0");
        DOMImplementationLS implLS = (DOMImplementationLS) domImpl;
        LSSerializer dom3Writer = implLS.createLSSerializer();

        LSOutput output = implLS.createLSOutput();

        output.setByteStream(outputStreamXML);
        output.setEncoding("UTF-8");
        dom3Writer.write(doc, output);

    }
}

Related

  1. saveToDisk(Document doc, OutputStream out)
  2. saveToFile(Document doc, File f, boolean indent)
  3. saveToFile(String filename, Document document)
  4. saveToXml(Document doc, OutputStream os)
  5. saveToXmlStr(Document doc)
  6. saveXML(Document doc, File outfile, boolean indent)
  7. saveXml(Document doc, String filename)
  8. saveXML(Document document, String filename)
  9. saveXml(Document dom, String filePath)