title: PHP - SimpleXML - AddChild with another SimpleXMLElement
body: <p>I'm trying to build a rather complex XML document.</p>
  
  <p>I have a bunch of sections of the XML document that repeats. I thought I'd use multiple string templates as base document for the sections and create instances of XML elements using simplexml_load_string.</p>
  
  <p>So I have one instance of SimpleXMLElement as the base document</p>
  
  <blockquote>
    <p>$root =
    simplexml_load_string($template_root);</p>
  </blockquote>
  
  <p>then I loop through some items in my database, create new SimpleXMLElement, something like this:</p>
  
  <blockquote>
    <p>for (bla bla bla):  </p>
    
    <p>$item = simplexml_load_string($template_item);
       // do stuff with item
       // try to add item to the root document..<br>
      // Stuck here.. can't do $root->items->addChild($item)</p>
    
    <p>endfor;</p>
  </blockquote>
  
  <p>I can't call addChild because it just expects a tag name and value.. you can't addChild another SimpleXMLElement.</p>
  
  <p>Am I missing something here? seems really dumb that addChild can't take a SimpleXMLELement as a parameter. </p>
  
  <p>Is there any other way to do this? (apart from using a different xml lib)</p>