Here you can find the source of writeToFile(String xmlContent, String path)
public static org.w3c.dom.Document writeToFile(String xmlContent, String path)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; public class Main { public static org.w3c.dom.Document writeToFile(String xmlContent, String path) { System.out.println("This is the path " + path); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;//from w w w. j a va 2s . co m try { builder = factory.newDocumentBuilder(); org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(xmlContent))); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(path)); transformer.transform(source, result); } catch (Exception e) { e.printStackTrace(); } return null; } }