title: Using PHP to convert XML to CSV but with a twist
body: <p>I'm trying to convert some XML files I have to CSV using PHP SimpleXML class. However, I'm unable to achieve the result I want, because one parent could have several child elements with the same name. My current XML file is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;root&gt;
      &lt;club&gt;
          &lt;name&gt;Green Riders&lt;/name&gt;
          &lt;membership&gt;Free&lt;/membership&gt;
          &lt;boardMember&gt;
              &lt;name&gt;James F.&lt;/name&gt;
              &lt;position&gt;CEO&lt;/position&gt;
          &lt;/boardMember&gt;
          &lt;boardMember&gt;
              &lt;name&gt;Helen D.&lt;/name&gt;
              &lt;position&gt;Associate Director&lt;/position&gt;
          &lt;/boardMember&gt;
      &lt;/club&gt;
      &lt;club&gt;
          &lt;name&gt;Broken Dice&lt;/name&gt;
          &lt;membership&gt;Paid&lt;/membership&gt;
          &lt;boardMember&gt;
              &lt;name&gt;Patrick B.&lt;/name&gt;
              &lt;position&gt;CEO&lt;/position&gt;
          &lt;/boardMember&gt;
      &lt;/club&gt;    
  &lt;/root&gt;
  </code></pre>
  
  <p>The CSV output I was hoping to achieve is as such:</p>
  
  <pre><code>club,name,membership,boardMember&gt;Name,boardMember&gt;position
  Green Riders,Free,James F.,CEO
  Green Riders,Free,Helen D., Associate Director
  Broken Dice,Paid,Patrick B., CEO
  </code></pre>
  
  <p>Is there anyway to achieve this without hard-coding the element names into the script (i.e. make it work on any generic XML file)?</p>
  
  <p>I'm really hoping this is possible, given that I'll be having more than 25 XML variants; so would really be inefficient to write a dedicated script for each.
  Thanks!</p>