List of utility methods to do XML Document to File
void | writeDomToFile(Document doc, String filename) write Dom To File TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult streamResult = new StreamResult(new File(filename)); transformer.transform(source, streamResult); |
void | writeDomToFile(Document dom, File outFile) write Dom To File try { TransformerFactory transFact = TransformerFactory.newInstance(); Transformer transformer = transFact.newTransformer(); DOMSource source = new DOMSource(dom); StreamResult result; result = new StreamResult( new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding"))); transformer.transform(source, result); ... |
void | writeDomToFile(Document dom, File outFile) write Dom To File try { Transformer transformer = transFactory.newTransformer(); DOMSource source = new DOMSource(dom); StreamResult result; result = new StreamResult( new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding"))); transformer.transform(source, result); } catch (Exception e) { ... |
void | writeDomToFile(Document dom, File outFile) write Dom To File try { TransformerFactory transFact = TransformerFactory.newInstance(); Transformer transformer = transFact.newTransformer(); DOMSource source = new DOMSource(dom); StreamResult result; result = new StreamResult( new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding"))); transformer.transform(source, result); ... |
void | writeDomToFile(String filename, Document document) This method writes a DOM document to a file try { Source source = new DOMSource(document); File file = new File(filename); Result result = new StreamResult(file); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } catch (TransformerConfigurationException e) { System.out.println("TransformerConfigurationException: " + e); ... |
void | writeFile(String fileName, Document content) write File writeFile(fileName, serializeDocument(content)); |
void | writeTo(Document document, File output) write To try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); FileOutputStream outputstream = new FileOutputStream(output); StreamResult result = new StreamResult(outputstream); String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; outputstream.write(xmlDeclaration.getBytes()); ... |
void | writeToFile(Document doc, String file) write To File TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMSource source = new DOMSource(doc); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); StreamResult result = new StreamResult(pw); transformer.transform(source, result); ... |
void | writeToFile(Document doc, String filePath) write To File Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); trans.transform(source, new StreamResult(new File(filePath))); |
void | writeToFile(File file, Document doc) write To File String xmlString = getXMLAsString(doc); try (FileOutputStream os = new FileOutputStream(file)) { byte[] xmlStringContent = xmlString.getBytes("UTF-8"); os.write(xmlStringContent); os.close(); |