title: appendChild using DOMDocument/PHP/XML
body: <p>I am trying to update my XML file based on an HTML form processed by PHP but the new XML snippet I am trying to append to specific areas of my current XML just keeps getting added to the end of my document. </p>
  
  <pre class="lang-php prettyprint-override"><code>$specific_node = "0"; //this is normally set by a select input from the form.
  $doc = new DOMDocument();
  $doc-&gt;load( 'rfp_files.xml' );
  $doc-&gt;formatOutput = true;
  
  //below is where my issue is having problems the variable '$specific_node' can be one of three options 0,1,2 and what I am trying to do is find the child of content_sets. So the first second or third child elemts and that is where I will add my new bit of XML
  $r = $doc-&gt;getElementsByTagname('content_sets')-&gt;item($specific_node);
  
  //This is where I build out my new XML to append
  $fileName = $doc-&gt;createElement("file_name");
  $fileName-&gt;appendChild(
      $doc-&gt;createTextNode( $Document_Array["url"] )
  );
  $b-&gt;appendChild( $fileName );
  
  //this is were I add the new XML to the child node mention earlier in the script. 
  $r-&gt;appendChild( $b );
  </code></pre>
  
  <p>XML Example:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;content_sets&gt;
    &lt;doc_types&gt;
      &lt;article&gt;
        &lt;doc_name&gt;Additional&lt;/doc_name&gt;
        &lt;file_name&gt;Additional.docx&lt;/file_name&gt;
        &lt;doc_description&gt;Test Word document. Please remove when live.&lt;/doc_description&gt;
        &lt;doc_tags&gt;word document,test,rfp template,template,rfp&lt;/doc_tags&gt;
        &lt;last_update&gt;01/26/2013 23:07&lt;/last_update&gt;
      &lt;/article&gt;
    &lt;/doc_types&gt;
    &lt;video_types&gt;
      &lt;article&gt;
        &lt;doc_name&gt;Test Video&lt;/doc_name&gt;
        &lt;file_name&gt;test_video.avi&lt;/file_name&gt;
        &lt;doc_description&gt;Test video. Please remove when live.&lt;/doc_description&gt;
        &lt;doc_tags&gt;test video,video, avi,xvid,svid avi&lt;/doc_tags&gt;
        &lt;last_update&gt;01/26/2013 23:07&lt;/last_update&gt;
      &lt;/article&gt;
    &lt;/video_types&gt;
    &lt;image_types&gt;
      &lt;article&gt;
       &lt;doc_name&gt;Test Image&lt;/doc_name&gt;
       &lt;file_name&gt;logo.png&lt;/file_name&gt;
       &lt;doc_description&gt;Logo transparent background. Please remove when live.&lt;/doc_description&gt;
       &lt;doc_tags&gt;png,logo,logo png,no background,graphic,hi res&lt;/doc_tags&gt;
       &lt;last_update&gt;01/26/2013 23:07&lt;/last_update&gt;
      &lt;/article&gt;
    &lt;/image_types&gt;
  &lt;/content_sets&gt;
  </code></pre>