title: Java DOM setAttribute not working
body: <p>Can someone tell me why this isn't work? It's driving me crazy.</p>
  
  <p>myFile.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;root date="oldValue" /&gt;     
  </code></pre>
  
  <p>Java Code</p>
  
  <pre><code>try {
      Document doc = builder.parse(new File("myFile.xml"));
      Element root = doc.getDocumentElement();
      System.out.println("date: " + root.getAttribute("date") + "\n");
      root.setAttribute("date", "test");
      System.out.println("date: " + root.getAttribute("date"));
  }  catch (Exception e)  {
      System.out.println("Something went wrong.");
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>oldValue
  oldValue
  </code></pre>
  
  <p>No matter what I do, I cannot get my code to write to the XML file... I've tried performing the setAttribute() function on child nodes of the root. I've tried just removing root... Nothing works. I'm beyond frustrated, so any help would be appreciated. Thanks.</p>