title: How to edit a node's value of an existing XML file from a SD card and save it back?
body: <p>I want to edit a node's value of an existing XML file from the SD card.</p>
  
  <p>For example if I want to edit <code>RouteName</code>'s value from <em>Mountain Trip</em> to <em>Sea Trip</em>.</p>
  
  <pre><code>&lt;Trip&gt; 
     &lt;RouteID&gt;12345&lt;/RouteID&gt;
     &lt;RouteName&gt;Mountain Trip&lt;/RouteName&gt;
  &lt;/Trip&gt;
  </code></pre>
  
  <p>I try to use the following code but it doesn't effect to the XML file on the SD card.</p>
  
  <pre class="lang-java prettyprint-override"><code>try {
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.parse(
          new File(Environment.getExternalStorageDirectory()+"/Trip/"+tripID+".trip"));
  
      Node nodes = doc.getElementsByTagName("RouteName").item(0);
      // newname is String variable which retrives value from edittext
      nodes.setNodeValue(newname);
  
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer();
  
      DOMSource source = new DOMSource(doc);
      StreamResult result = new StreamResult(
          new File(Environment.getExternalStorageDirectory()+"/Trip/"+tripID+".trip"));
      transformer.transform(source, result);
  } catch (Exception e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Why doesn't the XML file on the SD card get updated?</p>