title: Wrap an element for each set of elements with SimpleXML/DOMDocument
body: <p>I have the code below to create a XML file</p>
  
  <pre><code>&lt;?php
   try
  {
      $dom = new domDocument;
      $dom-&gt;formatOutput = true;
      $root = $dom-&gt;appendChild($dom-&gt;createElement( "items" ));
      $sxe = simplexml_import_dom( $dom );
  
      $sxe-&gt;addChild("model", "HTC Desire");
      $sxe-&gt;addChild("model", "Motorola Atrix");
      echo $sxe-&gt;asXML();
  }
  catch( Exception $e )
  {
      echo $e-&gt;getMessage();
  }
  ?&gt;
  </code></pre>
  
  <p>While execute this code, it will generate the content likes:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;items&gt;
  &lt;model&gt;HTC Desire&lt;/model&gt;
  &lt;model&gt;Motorola Atrix&lt;/model&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>But, I would like to wrap an element called <code>item</code> for each model, the result should be:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;items&gt;
  &lt;item&gt;&lt;model&gt;HTC Desire&lt;/model&gt;&lt;/item&gt;
  &lt;item&gt;&lt;model&gt;Motorola Atrix&lt;/model&gt;&lt;/item&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>Anyone could suggest how to do this?</p>