title: How to add an element in this XML file using DOM parser?
body: <p>I want to know how can I modify this XML file,</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;nombre&gt;
      &lt;id&gt;12345&lt;/id&gt;
  &lt;/nombre&gt;
  </code></pre>
  
  <p>into a XML file like this using DOM parser in Java,</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
      &lt;heat&gt;2013-09-09&lt;/heat&gt;
      &lt;nombre&gt;
        &lt;id&gt;12345&lt;/id&gt;
      &lt;/nombre&gt;
  </code></pre>
  
  <p>I have tried this but doesn't work,</p>
  
  <pre><code>public class Test {
  
  public static final String xmlFilePath = "src/vnx.xml";
  public static final String xml2FilePath = "src/input2.xml";
  
  public static void main(String argv[]) {
  
      try {
  
          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
          Document document = documentBuilder.parse(xmlFilePath);
  
          Element version = document.createElement("heat");
          version.appendChild(document.createTextNode("2013-09-09"));
          document.appendChild(version);
  
  
  
          TransformerFactory transformerFactory = TransformerFactory.newInstance();
  
          Transformer transformer = transformerFactory.newTransformer();
          DOMSource domSource = new DOMSource(document);
  
          StreamResult streamResult = new StreamResult(new File(xml2FilePath));
          transformer.transform(domSource, streamResult);
  
  
      } catch (ParserConfigurationException pce) {
          pce.printStackTrace();
      } catch (TransformerException tfe) {
          tfe.printStackTrace();
      } catch (IOException ioe) {
          ioe.printStackTrace();
      } catch (SAXException sae) {
          sae.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It returns a parsing error. Any suggestion would be really helpful. Thanks a lot!</p>