import java.io.File; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 WriteToFileDomDocument{ public static void main(String[] args) throws Exception { Document doc = null; Source src= new DOMSource(doc); File file = new File("writeToFileDomDocument"); Result rs = new StreamResult(file); TransformerFactory tmf = TransformerFactory.newInstance(); Transformer trnsfrmr = tmf.newTransformer(); trnsfrmr.transform(src, rs); System.out.println("XML file is created successfully"); } }