title: how to append tags in xml in android? and how save that xml file?
body: <p>i would like to append a new tag with some attributes with those values in to xml file and save that xml file through my application.i have written a method for append a new tag as child to xml file which is available in sdcard of android emulator.the following method for append a new tag as follows</p>
  
  <pre><code>   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);
  
       //append a new node to earth
       Element newelmnt = doc.createElement("new");
       newelmnt.appendChild(doc.createTextNode("this is a text"));
       node.appendChild(newelmnt);
  
  
      }
      catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>after execution of this method i can't able to find a new tag in xml file.</p>
  
  <p>could please any one help on how to append new tag as child in xml file and how save the modification?</p>
  
  <p>if i uses TransformerFactory i am getting error as 
     <strong>ERROR/AndroidRuntime(13479): java.lang.VerifyError: com.sample.xmlapp.DOMClass</strong>
  i have used as follows</p>
  
  <pre><code>     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);
  </code></pre>