Java XML Document to Writer toXML(Document doc, Writer w, boolean indent)

Here you can find the source of toXML(Document doc, Writer w, boolean indent)

Description

to XML

License

Open Source License

Declaration

public static void toXML(Document doc, Writer w, boolean indent) throws IOException 

Method Source Code

//package com.java2s;
/*************************************************************************
 **/*from  w  w  w.  j  a  v a  2 s.c om*/
 ** Copyright (C) 2007      Jan de Visser. All rights reserved.
 **
 ** This file may be used under the terms of the GNU General Public
 ** License version 2.0 as published by the Free Software Foundation
 ** and appearing in the file LICENSE.GPL included in the packaging of
 ** this file.  Please review the following information to ensure GNU
 ** General Public Licensing requirements will be met:
 ** http://www.trolltech.com/products/qt/opensource.html
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/

import java.io.IOException;

import java.io.Writer;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
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 {
    private static TransformerFactory s_xformer_factory = TransformerFactory.newInstance();

    public static void toXML(Document doc, Writer w, boolean indent) throws IOException {
        try {
            Source source = new DOMSource(doc);
            Result result = new StreamResult(w);
            Transformer xformer = s_xformer_factory.newTransformer();
            xformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("Configuration Exception writing XML: " + e);
        } catch (TransformerException e) {
            throw new RuntimeException("Exception writing XML: " + e);
        }
    }
}

Related

  1. toWriter(Document doc, Writer writer)
  2. write(Writer out, Document doc)
  3. writeDocument(Document doc, Writer out)
  4. writeDocument(Document doc, Writer w)
  5. writeDocument(Document document, Writer writer, Integer indent)