title: Append nodes into existing XML File with java
body: <p>Hi im looking for a solution to append nodes from java into an existing xml file.
  What i got is an xml file like this</p>
  
  <pre><code>&lt;data&gt;
  &lt;people&gt;
      &lt;person&gt;
          &lt;firstName&gt;Frank&lt;/firstName&gt;
          &lt;lastName&gt;Erb&lt;/lastName&gt;
          &lt;access&gt;true&lt;/access&gt;
          &lt;images&gt;
              &lt;img&gt;hm001.jpg&lt;/img&gt;
          &lt;/images&gt;
      &lt;/person&gt;
      &lt;person&gt;
          &lt;firstName&gt;Hans&lt;/firstName&gt;
          &lt;lastName&gt;Mustermann&lt;/lastName&gt;
          &lt;access&gt;true&lt;/access&gt;
          &lt;images&gt;
              &lt;img&gt;hm001.jpg&lt;/img&gt;
          &lt;/images&gt;
      &lt;/person&gt;
      &lt;person&gt;
          &lt;firstName&gt;Thomas&lt;/firstName&gt;
          &lt;lastName&gt;Tester&lt;/lastName&gt;
          &lt;access&gt;false&lt;/access&gt;
          &lt;images&gt;
              &lt;img&gt;tt001.jpg&lt;/img&gt;
          &lt;/images&gt;
      &lt;/person&gt;
  &lt;/people&gt;
   &lt;/data&gt;
  </code></pre>
  
  <p>what i whant to  add is a person node with its elements inside the people element. My big problem is the data node which is root node. If it would be the Person node as root I could solve it. But I can't manage to get the person nodes under the people node.</p>
  
  <pre><code>           &lt;person&gt;
          &lt;firstName&gt;Tom&lt;/firstName&gt;
          &lt;lastName&gt;Hanks&lt;/lastName&gt;
          &lt;access&gt;false&lt;/access&gt;
          &lt;images&gt;
              &lt;img&gt;tt001.jpg&lt;/img&gt;
          &lt;/images&gt;
      &lt;/person&gt;
  </code></pre>
  
  <p>thanks for your help!</p>
  
  <p>my java code looks as far like this</p>
  
  <pre><code>Element root = document.getDocumentElement();
  
  
  // Root Element
  Element rootElement = document.getDocumentElement();
  
  Collection&lt;Server&gt; svr = new ArrayList&lt;Server&gt;();
  svr.add(new Server());
  
  for (Server i : svr) {
      // server elements
  
      Element server = document.createElement("people");
      rootElement.appendChild(server);
      //rootElement.appendChild(server);
  
      Element name = document.createElement("person");
      server.appendChild(name);
  
      Element firstName = document.createElement("firstName");
      firstName.appendChild(document.createTextNode(i.getFirstName()));
      server.appendChild(firstName);
      name.appendChild(firstName);
  
      Element port = document.createElement("lastName");
      port.appendChild(document.createTextNode(i.getLastName()));
      server.appendChild(port); 
      name.appendChild(port);
  
      Element access = document.createElement("access");
      access.appendChild(document.createTextNode(i.getAccess()));
      server.appendChild(access); 
      name.appendChild(access);
  
      String imageName = Main.randomImgNr+"";
      Element images = document.createElement("images");
      //images.appendChild(document.createTextNode(i.getAccess()));
      Element img = document.createElement("img");
      img.appendChild(document.createTextNode(imageName));//i.getImage()));
      images.appendChild(img);            
  
      server.appendChild(images);
      name.appendChild(images);
      root.appendChild(server);
  </code></pre>