title: PHP - Read file in folder and subfolders and export to XML file
body: <p>I get this</p>
  
  <blockquote>
    <p>XML Parsing Error: junk after document element
    Location: xxxxxxxxx
    Line Number 2, Column 1</p>
  </blockquote>
  
  <p>This is the code :</p>
  
  <pre><code>&lt;?php
  
  $xml_generator = new SimpleXMLElement('&lt;data/&gt;');
  
  filesindir('assets/images/');
  function filesindir($dirs) {
      $dirs = scandir($tdir);
      while ($file = readdir($dirs)) {
              if (($file == '.')||($file == '..')) {
              } elseif (is_dir($tdir.'/'.$file)) {
                  filesInDir($tdir.'/'.$file);
              } else {
                  $image = $xml_generator-&gt;addChild('image');  
                  $image-&gt;addChild('name', $file);
              }
      }
  }
  
  header("Content-Type: text/xml");
  $xml_generator-&gt;asXML('data.xml');
  echo $xml_generator-&gt;asXML();
  ?&gt;
  </code></pre>
  
  <p>What did I do wrong?</p>