title: how to correctly append xml child elements in php
body: <p>I'm trying to iterate over an array of movie names and am struggling as shown below. I've included the actual output vs expected output.  thanks!</p>
  <pre><code>$root = new SimpleXMLElement('&lt;movies/&gt;');
  $movies = ['foo', 'bar'];
  foreach($movies as $movie_name){
      $movie_el = buildMovieTag($movie_name);
      $root-&gt;addChild($movie_el-&gt;asXML());
  }
  
  
  function buildMovieTag($name){
      $movie_tag = new SimpleXMLElement('&lt;movie/&gt;');
      $movie_tag-&gt;addChild('name', $name);
      return $movie_tag;
  }
  </code></pre>
  <p>I'm expecting this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;movies&gt;
  &lt;movie&gt;&lt;name&gt;foo&lt;/name&gt;&lt;/movie&gt;
  &lt;movie&gt;&lt;name&gt;bar&lt;/name&gt;&lt;/movie&gt;
  &lt;/movies&gt;
  </code></pre>
  <p>but am getting this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;movies&gt;&lt;&lt;?xml version=&quot;1.0&quot;?&gt;  // extra xml tag
  &lt;movie&gt;&lt;name&gt;foo&lt;/name&gt;&lt;/movie&gt;
  /&gt;&lt;&lt;?xml version=&quot;1.0&quot;?&gt; // extra xml tag
  &lt;movie&gt;&lt;name&gt;bar&lt;/name&gt;&lt;/movie&gt;
  /&gt;&lt;/movies&gt;
  </code></pre>