Java XML Document to Writer writeOutDOM(Document doc, Writer writer)

Here you can find the source of writeOutDOM(Document doc, Writer writer)

Description

write Out DOM

License

Apache License

Declaration

static void writeOutDOM(Document doc, Writer writer)
            throws TransformerFactoryConfigurationError, TransformerException 

Method Source Code

//package com.java2s;
/*/* w ww  .  j a v  a2  s  .c om*/
 * Copyright (c)2016 General Networks Corporation 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * 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. 
 * 
 * The use of the Apache License does not indicate that this project is 
 * affiliated with the Apache Software Foundation. 
 */

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;

import java.io.*;

public class Main {
    static void writeOutDOM(Document doc, Writer writer)
            throws TransformerFactoryConfigurationError, TransformerException {
        Result result = new StreamResult(writer);
        DOMSource domSource = new DOMSource(doc);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty("omit-xml-declaration", "yes");
        transformer.transform(domSource, result);
    }
}

Related

  1. writeDocument(Document doc, Writer out)
  2. writeDocument(Document doc, Writer w)
  3. writeDocument(Document document, Writer writer, Integer indent)
  4. writeDocument(PrintWriter w, Document d)
  5. writeDom(Document doc, Writer w)
  6. writeXML(final Document doc, final Writer writer)