title: How to add children to childnodes using jsoup document
body: <p><strong>I am trying to create the following example.</strong></p>
  
  <pre><code>&lt;body&gt;
    &lt;resources&gt;
      &lt;string-array name="mytest"&gt;
        &lt;item number="1"&gt;
          &lt;name&gt;Testname&lt;/name&gt;
        &lt;/item&gt;
        &lt;item number="2"&gt;
          &lt;name&gt;blaat..&lt;/name&gt;
        &lt;/item&gt;
      &lt;/string-array&gt;
    &lt;/resources&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>I try this by doing the following:</strong></p>
  
  <pre><code>FileInputStream fis = openFileInput("test1.xml");
  
  Document doc = Jsoup.parse(fis, "UTF-8", "");
  Node node = doc.getElementsByTag("item").get(getPosition());
  
  fis.close();
  fis = openFileInput("test2.xml");
  Document doc2 = Jsoup.parse(fis, "UTF-8", "");
  fis.close();
  
  Elements test = doc2.getElementsByTag("resources");
  if(test.size() &lt; 0){
  fis = openFileInput("test2.xml");
  doc2 = Jsoup.parse(fis, "UTF-8", "");
  fis.close();
  doc2.appendElement("resources").parent();
  FileOutputStream os = openFileOutput("test2.xml", Context.MODE_PRIVATE);
  os.write(doc2.toString().getBytes());
  os.close();
  
  fis = openFileInput("test2.xml");
  doc2 = Jsoup.parse(fis, "UTF-8", "");
  fis.close();
  doc2.appendChild(doc2.appendElement("string-array").attr("name", "mytest")).parent();
  os = openFileOutput("test2.xml", Context.MODE_PRIVATE);
  os.write(doc2.toString().getBytes());
  os.close();
  
  System.out.println("Created file\n");
  }
  
  doc2.appendChild(node);
  FileOutputStream os = openFileOutput("test2.xml", Context.MODE_PRIVATE);
  
  os.write(doc2.toString().getBytes()); 
  os.close();
  </code></pre>
  
  <p><strong>And what i get now is:</strong></p>
  
  <pre><code>&lt;!-- test1.xml (input) --&gt;
  &lt;resources&gt;
    &lt;string-array name="firsttest"&gt;
      &lt;item number="1"&gt;
        &lt;name&gt;Testname&lt;/name&gt;
      &lt;/item&gt;
      &lt;item number="2"&gt;
        &lt;name&gt;blaat..&lt;/name&gt;
      &lt;/item&gt;
      &lt;item number="3"&gt;
        &lt;name&gt;Next item&lt;/name&gt;
      &lt;/item&gt;
    &lt;/string-array&gt;
  &lt;/resources&gt;
  
  &lt;!-- test2.xml (output)--&gt;
  &lt;body&gt;
    &lt;resources&gt;&lt;/resources&gt;
    &lt;string-array name="mytest"&gt;&lt;/string-array&gt;
    &lt;item number="1"&gt;
      &lt;name&gt;Testname&lt;/name&gt;
    &lt;/item&gt;
    &lt;item number="2"&gt;
      &lt;name&gt;blaat..&lt;/name&gt;
    &lt;/item&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Can anybody tell me what i'm doing wrong and maybe give me some examples on how it should be done?</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT: To give a bit more detail: I want to copy some items from test1.xml to test2.xml. So basically the user selects a listitem that points to a number in text1.xml (item number) and that item should then be copied into the  (ITEM HERE </p>