I would like to add a new tag with some attributes with these values ββto an xml file and save this XML file through the application. I wrote a method to add a new tag as a child in the xml file, which is available in the sdcard of the android emulator.The next method is to add a new tag as follows
public void appendTag(){ try{ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse (new File("/sdcard/sample.xml")); Node node = doc.getElementsByTagName("earth").item(0);
after executing this method, I cannot find the new tag in the XML file.
may any help on how to add a new tag as a child in an xml file and how to save the changes?
If I use TransformerFactory, I get an error like ERROR / AndroidRuntime (13479): java.lang.VerifyError: com.sample.xmlapp.DOMClass I used the following
TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File("/sdcard/sample.xml")); transformer.transform(source, result);
prasad.gai
source share