title: SimpleXMLElement::addChild() is not working
body: <p>In my php code I have two variables <code>$parent</code> and <code>$child</code>. Both of them have some xml data. in <code>$parent</code> variable there is a tag called <code>&lt;payheads&gt;</code> which may contain several <code>&lt;payhead&gt;</code> tags. In <code>$child</code> variable there is only one <code>&lt;payhead&gt;</code> tag. What I want is, I want to add that child in the end of the <code>&lt;payheads&gt;</code> tag of <code>$parent</code> variable. My Code is given below:  </p>
  
  <pre><code>&lt;?php
  
  $parent = new SimpleXMLElement('&lt;review_sr&gt;&lt;status&gt;Review Complete&lt;/status&gt;&lt;payheads&gt;&lt;payhead&gt;&lt;code&gt;ABAS&lt;/code&gt;&lt;old_value&gt;0.00&lt;/old_value&gt;&lt;new_value&gt;63570.00&lt;/new_value&gt;&lt;review_id&gt;1234567890&lt;/review_id&gt;&lt;review_time&gt;20160614:11:00:47&lt;/review_time&gt;&lt;status&gt;Accepted&lt;/status&gt;&lt;/payhead&gt;&lt;/payheads&gt;&lt;current_gross_allowance&gt;50481.00&lt;/current_gross_allowance&gt;&lt;review_gross_allowance&gt;114051.00&lt;/review_gross_allowance&gt;&lt;/review_sr&gt;');
  
  $child = new SimpleXMLElement('&lt;source&gt;&lt;payhead&gt;&lt;code&gt;DMG&lt;/code&gt;&lt;old_value&gt;500.00&lt;/old_value&gt;&lt;new_value&gt;0.00&lt;/new_value&gt;&lt;review_id&gt;1234567890&lt;/review_id&gt;&lt;review_time&gt;20160620:12:41:17&lt;/review_time&gt;&lt;status&gt;Accepted&lt;/status&gt;&lt;/payhead&gt;&lt;/source&gt;');
  $child = $child-&gt;xpath('//payhead'); //This is to ignore the xml declaration that is automatically produced by the SimpleXMLElement constructor
  $child = $child[0];                 //I've tried LIBXML_NOXMLDECL  but its not working, that's why these two lines.
  
  //var_dump($parent);
  //var_dump($child-&gt;asXML());
  
  $parentNode = $parent-&gt;xpath('//payheads');
  $parentNode[0]-&gt;addChild('payhead', $child);
  //var_dump($parentNode[0]);
  foreach($parent as $key=&gt;$value)
      foreach($value as $key=&gt;$value)
          var_dump($value); //only 1 payhead is shown. but there should be 2 of them.
  
  ?&gt;  
  </code></pre>
  
  <p>Actual Output:  </p>
  
  <pre><code>object(SimpleXMLElement)[5]
    public 'code' =&gt; string 'ABAS' (length=4)
    public 'old_value' =&gt; string '0.00' (length=4)
    public 'new_value' =&gt; string '63570.00' (length=8)
    public 'review_id' =&gt; string '1234567890' (length=10)
    public 'review_time' =&gt; string '20160614:11:00:47' (length=17)
    public 'status' =&gt; string 'Accepted' (length=8)
  
  object(SimpleXMLElement)[6]
  </code></pre>
  
  <p>Expected Output:  </p>
  
  <pre><code>object(SimpleXMLElement)[5]
    public 'code' =&gt; string 'ABAS' (length=4)
    public 'old_value' =&gt; string '0.00' (length=4)
    public 'new_value' =&gt; string '63570.00' (length=8)
    public 'review_id' =&gt; string '1234567890' (length=10)
    public 'review_time' =&gt; string '20160614:11:00:47' (length=17)
    public 'status' =&gt; string 'Accepted' (length=8)
  
  object(SimpleXMLElement)[6]  
    public 'code' =&gt; string 'DMG' (length=4)
    public 'old_value' =&gt; string '500.00' (length=4)
    public 'new_value' =&gt; string '0.00' (length=8)
    public 'review_id' =&gt; string '1234567890' (length=10)
    public 'review_time' =&gt; string '20160620:12:41:17' (length=17)
    public 'status' =&gt; string 'Accepted' (length=8)
  </code></pre>
  
  <p>What did I do wrong?</p>