This method writes the DOM document to a file on the SD card. If you want to test this in the emulator, make sure your AVD image is set using the SD card image (taken during image creation).
public static void writeXmlFile(Document doc, String filename) { try { // Prepare the DOM document for writing Source source = new DOMSource(doc); File file new File(Environment.getExternalStorageDirectory(),fileName); Result result = new StreamResult(file); // Write the DOM document to the file Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } catch (TransformerConfigurationException e) { // handle exception } catch (TransformerException e) { // handle exception } }
source share