title: How to create XML file without XML opening tags
body: <p>I'm using PHP to create an XML file, this was quite challenging for me as I'm not an expert when it comes to PHP, however the output is not as desired. Question: How do I create my desired output?</p>
  
  <p><strong>Clarification:</strong> I need this because this file will get merged into another dynamically created XML file where the XML opening tags would cause the following error: <code>XML declaration allowed only at the start of the document</code>.</p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;items&gt;
    &lt;page description="template4" type="4" duration="5000" on="saturday"/&gt;
    &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
    &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
    &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
    &lt;page description="template4" type="4" duration="5000" on="today"/&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p><strong>Desired output:</strong> (I know this is not valid XML but it is still called a <code>.xml</code> file per definition).</p>
  
  <pre><code>&lt;page description="template4" type="4" duration="5000" on="saturday"/&gt;
  &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
  &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
  &lt;page description="template4" type="4" duration="5000" on="sunday"/&gt;
  &lt;page description="template4" type="4" duration="5000" on="today"/&gt;
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>$xmldata = new SimpleXMLElement('&lt;items /&gt;');
  
  for ($i=0; $i &lt; count($_POST['data']); $i++) {
    $xmlpage = $xmldata-&gt;addChild('page');
    $xmlpage-&gt;addAttribute('description', 'template4');
    $xmlpage-&gt;addAttribute('type', '4');
    $xmlpage-&gt;addAttribute('duration', '5000');
    $xmlpage-&gt;addAttribute('on', $_POST['data']['bday' . $i . '']['when']);
  }
  
  $xmldata-&gt;asXML('xml/playlistbdays.xml');
  </code></pre>
  
  <p><strong>I tried:</strong></p>
  
  <p><li><code>$xmldata = new SimpleXMLElement('');</code> which gives an error saying: <code>String could not be parsed as XML</code>.</li></p>