title: Java - Add to DOM XML File
body: <p>I have the following XML, I would like to add another "product" to the xml.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;products&gt;
      &lt;product&gt;
          &lt;name&gt;Computer&lt;/name&gt;
          &lt;code&gt;PC1003&lt;/code&gt;
          &lt;description&gt;Basic Computer&lt;/description&gt;
          &lt;price&gt;399.99&lt;/price&gt;
      &lt;/product&gt;
      &lt;product&gt;
          &lt;name&gt;Monitor&lt;/name&gt;
          &lt;code&gt;MN1003&lt;/code&gt;
          &lt;description&gt;LCD Monitor&lt;/description&gt;
          &lt;price&gt;99.99&lt;/price&gt;
      &lt;/product&gt;
      &lt;product&gt;
          &lt;name&gt;Printer&lt;/name&gt;
          &lt;code&gt;PR1003x&lt;/code&gt;
          &lt;description&gt;Inkjet Printer&lt;/description&gt;
          &lt;price&gt;54.23&lt;/price&gt;
      &lt;/product&gt;
  &lt;/products&gt;
  </code></pre>
  
  <p>This is the code I have so far:</p>
  
  <pre><code>        // Variables
          File file = new File("db_products.xml"); // set xml to parse
  
          // Create builders
          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
          Document doc = dBuilder.parse(file); // load xml file
          doc.getDocumentElement().normalize();
  
          doc.createElement("product");
  </code></pre>
  
  <p>I don't really care where the new "product" section is added. I just can't seem to grasp what is the difference between a node and an element. I'm assuming the correct way to add a new "product" section would be to add a child to "products" and then add children (name,code,etc.) to "product".</p>
  
  <p>Any help on how to easily do this, or a link to a simple tutorial would be appreciated. </p>