Here you can find the source of writeXML(Document doc, OutputStream os)
Parameter | Description |
---|---|
doc | a parameter |
os | a parameter |
Parameter | Description |
---|---|
TransformerException | an exception |
IOException | an exception |
public static void writeXML(Document doc, OutputStream os) throws TransformerException, IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; 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 { /**/*from w w w . j a v a 2 s . co m*/ * write out an XML file * * @param doc * @param os * @throws TransformerException * @throws IOException */ public static void writeXML(Document doc, OutputStream os) throws TransformerException, IOException { // write out xml file TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //indent XML properly //formatXML(doc,doc.getDocumentElement()," "); //normalize document doc.getDocumentElement().normalize(); //write XML to file DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(os); transformer.transform(source, result); os.close(); } }