title: Java - How to add XML element to root tag?
body: <p>I have an XML File that looks like this:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' standalone='yes' ?&gt;
  &lt;allinfo&gt;
    &lt;filepath&gt;/mnt/sdcard/Audio_Recorder/&lt;/filepath&gt;
    &lt;filename&gt;newxml35500.3gp&lt;/filename&gt;
    &lt;annotation&gt;
      &lt;file&gt;newxml35500.3gp&lt;/file&gt;
      &lt;timestamp&gt;0:05&lt;/timestamp&gt;
      &lt;note&gt;uuuouou&lt;/note&gt;
    &lt;/annotation&gt;
    &lt;filepath&gt;/mnt/sdcard/Audio_Recorder/&lt;/filepath&gt;
    &lt;filename&gt;newxml35501.3gp&lt;/filename&gt;
    &lt;annotation&gt;
      &lt;file&gt;newxml35501.3gp&lt;/file&gt;
      &lt;timestamp&gt;0:04&lt;/timestamp&gt;
      &lt;note&gt;tyty&lt;/note&gt;
    &lt;/annotation&gt;
  &lt;/allinfo&gt;
  </code></pre>
  
  <p>I am trying to add an addition annotation to the XML after it has been created so the XML has an additional:</p>
  
  <pre><code>&lt;annotation&gt;
    &lt;file&gt;blah&lt;/file&gt;
    &lt;timestamp&gt;0:00&lt;/timestamp&gt;
    &lt;note&gt;this is a note&lt;/note&gt;
  &lt;/annotation&gt;
  </code></pre>
  
  <p>What is the best way to find the root and then write a few lines to the XML in Java? I have seen DocumentBuilderFactory get some use from others but I am not sure how to implement it correctly. Any help would be much appreciated.</p>