title: How to replace old value between XML tags with new value
body: <p>I have to replace the <code>oldValue</code> in the date tag with the <code>newValue</code> in the below XML. I am using <code>setAttribute</code> function to do that but it doesn't seem to work. Please do let me know if I have to use a different function for replace text between tags.</p>
  
  <p><em>myfile.xml</em>  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;  
  &lt;root&gt;  
          &lt;date&gt;oldValue&lt;/date&gt;  
  &lt;/root&gt;
  </code></pre>
  
  <p><em>replace.java</em></p>
  
  <pre><code>Document doc = builder.parse(new File("myFile.xml"));  
  Element root = doc.getDocumentElement();  
  System.out.println("Before");  
  System.out.println("Using getElementByTagName date: " + root.getElementsByTagName("date").item(0).getTextContent());  
  System.out.println("Using getAttribute        date: " + root.getAttribute("date"));
  root.setAttribute("date", "newValue");  
  System.out.println("After");  
  System.out.println("Using getElementByTagName date: " + root.getElementsByTagName("date").item(0).getTextContent());  
  System.out.println("Using getAttribute        date: " + root.getAttribute("date"));
  </code></pre>
  
  <p><em>Output:</em>  </p>
  
  <pre><code>**Before**  
   Using getElementByTagName date: oldValue  
   Using getAttribute        date:  
   **After**  
   Using getElementByTagName date: oldValue  
   Using getAttribute        date: test  
  </code></pre>
  
  <p>With the a lot of reading/experimentation, I have found <code>setAttribute()</code> works for replacing an XML like this. But, this doesn't work for me.  </p>
  
  <p><br>
      </p>