Java XML Document to String write2Xml(Document document)

Here you can find the source of write2Xml(Document document)

Description

write Xml

License

Apache License

Declaration

public static void write2Xml(Document document) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.FileOutputStream;

import javax.xml.transform.Transformer;
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 String fileName = "src/main/resources/xml/exam.xml";

    public static void write2Xml(Document document) throws Exception {
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer tf = factory.newTransformer();
        tf.transform(new DOMSource(document), new StreamResult(new FileOutputStream(fileName)));
    }/* ww  w .  j a v  a  2s.  c o  m*/
}

Related

  1. toXMLString(Document doc, boolean includeXMLDecl, boolean indent)
  2. toXmlString(Document document)
  3. write(Document doc)
  4. write(Document doc, Result result)
  5. write(String filename, Document document, boolean addDocType)
  6. write2xml(Document document)
  7. write_DOM_into_an_HTML_file(Document doc, String htmlFile, String xslFile)
  8. writeDocument(Document doc, boolean omitXmlDeclaration)
  9. writeDocument(Document document)