List of utility methods to do XML Document to File
void | writeDocument(Document doc, String filename) Writes a Document to a file. writeDocument(doc, filename, false); |
void | writeDocument(Document doc, String filePath) Properly formats a DOM object and writes it to the filesystem. OutputStream os; os = new FileOutputStream(filePath); os.write(format(doc).getBytes("US-ASCII")); os.close(); |
void | writeDocument(Document doc, String filePath) write Document Path pathToFile = Paths.get(filePath);
Files.createDirectories(pathToFile.getParent());
writeDocument(doc, new FileOutputStream(filePath));
|
void | writeDocument(Document document, File file) write Document TransformerFactory transformFactory = TransformerFactory.newInstance(); Transformer idTransform = transformFactory.newTransformer(); Source input = new DOMSource(document); Result output = new StreamResult(file); idTransform.transform(input, output); |
void | writeDocument(Document document, File file) Writes a document to a file. file.getParentFile().mkdirs(); file.createNewFile(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(file); getTransformer(document.getDoctype()).transform(source, result); |
void | writeDocument(Document document, String path) write Document TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMSource source = new DOMSource(document); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); File file = new File(path); if (!file.exists()) { File parent = file.getParentFile(); ... |
void | writeDocumentTo(Document doc, File file) Writes the given Document to a File . final FileOutputStream fos = new FileOutputStream(file); try { writeDocumentTo(doc, fos); } finally { fos.close(); |
void | writeDocumentToFile(Document document, String filePathname, String method, int indent) Write the document object to a file. Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, method); transformer.transform(new DOMSource(document), new StreamResult(new FileOutputStream(filePathname))); |
void | writeDOM2XMLFile(Document domDoc, String fileName) write the dom content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); DOMSource source = new DOMSource(domDoc); ... |
void | writeDOMDocumentToFile(Document doc, String filePath) Persists a DOM document to a file File outFile = new File(filePath); File outDir = new File(outFile.getParent()); outDir.mkdir(); FileOutputStream stream = null; try { stream = new FileOutputStream(outFile); writeDOMDocumentToStream(doc, stream); } finally { ... |