title: R - How to convert XML to dataframe in R with the correct structure?
body: <p>I would like to convert an XML file into a dataframe. I have found some functions which allow me to read the XML data, however I am not able to get a dataframe with the same structure as the initial XML file (= structure that you would get if you open the XML file in Excel).</p>
  
  <p>This is my original XML code:</p>
  
  <pre><code>&lt;Data&gt;
  &lt;Frame timestamp='17/09/2014  20:55:00.902' timecode='75299902' &gt;
  &lt;Object type='Taxi' DISTANCE='3037' VOLUME='1668' id='15593' code='0' /&gt;
  &lt;Object type='Taxi' DISTANCE='3605' VOLUME='931' id='15603' code='4' /&gt;
  &lt;Object type='Bus' DISTANCE='3563' VOLUME='488' id='15604' code='9' /&gt;
  &lt;Object type='Taxi' DISTANCE='4942' VOLUME='57' id='15624' code='1' /&gt;
  &lt;Object type='Taxi' DISTANCE='784' VOLUME='47' id='15625' code='10' /&gt;
  &lt;Object type='Taxi' DISTANCE='3301' VOLUME='2041' id='15626' code='42' /&gt;
  &lt;Object type='Bus' DISTANCE='2040' VOLUME='2945' id='15630' code='27' /&gt;
  &lt;Object type='Airplane' DISTANCE='2865' VOLUME='2722' Z='0' /&gt;
  &lt;/Frame&gt;
  &lt;TrackingFrame timestamp='17/09/2014 20:54:59.771' timecode='75299771' &gt;
  &lt;Object type='Taxi' DISTANCE='4941' VOLUME='51' id='15624' code='1' /&gt;
  &lt;Object type='Taxi' DISTANCE='789' VOLUME='47' id='15625' code='10' /&gt;
  &lt;Object type='Taxi' DISTANCE='3300' VOLUME='2069' id='15626' code='42' /&gt;
  &lt;Object type='Bus' DISTANCE='2027' VOLUME='2947' id='15630' code='27' /&gt;
  &lt;Object type='Airplane' DISTANCE='2865' VOLUME='2722' Z='0' /&gt;
  &lt;/Frame&gt;
  &lt;/Data&gt;
  </code></pre>
  
  <p>This allows me already to get a list of the data:
  library(XML)</p>
  
  <pre><code># Convert xml data to R
  data &lt;- xmlTreeParse(file="c:/R/CL/filename.xml",useInternalNode=TRUE)
  # Create a list of the data
  xl&lt;-xmlToList(data)
  </code></pre>
  
  <p>Ideally I would like to get a dataframe based on this XML data that looks the same as when you would input the XML data in Excel. However, when I look at the output of xl then I see that this is organized in Objects and Times. Normally when I open the XML files in Excel this information is linked (and every Object has also columns with Time information)</p>
  
  <p>This is the output of xl&lt;-xmlToList(data):</p>
  
  <pre><code>$Frame$Object
       type         DISTANCE         VOLUME        id       code 
  "Taxi"    "3037"    "1668"   "15593"       "0" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "3605"   "931" "15603"     "4" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   “Bus”  "3563"   "488" "15604"     "9" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "2161"  "1592" "15615"    "21" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "4942"    "57" "15624"     "1" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"   "784"    "47" "15625"    "10" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "3301"  "2041" "15626"    "42" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   “Bus”  "2040"  "2945" "15630"    "27" 
  
  
  $Frame$Object
    type      DISTANCE      VOLUME      Z 
  "Airplane" "2865" "2722"    "0" 
  
  $Frame$Time
                  timestamp                  timecode 
  "17/09/2014 20:54:59.902"                "75299902"
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "4941"    "51" "15624"     "1" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"   "789"    "47" "15625"    "10" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   "Taxi"  "3300"  "2069" "15626"    "42" 
  
  $Frame$Object
     type       DISTANCE       VOLUME      id     code 
   “Bus”  "2027"  "2947" "15630"    "27" 
  
  $Frame$Object
    type      DISTANCE      VOLUME      Z 
  "Airplane" "2865" "2722"    "0" 
  
  $Frame$Time
                  timestamp                  timecode 
  "17/09/2014 20:54:59.771"                "75299771"
  </code></pre>
  
  <p>This lists contains 2 table structures / frames: Frame$Object and Frame$Time. I would like to combine these 2 structures into one combined table (by repeating the columns timestamp and timecode with the time information for every Object).</p>
  
  <p>See here below the desired output (with the same structure as when you would enter the XML file in Excel):</p>
  
  <pre><code>type    DISTANCE    VOLUME  id  code    z   timestamp   timecode
  Taxi    3037    1668    15593   0       17/09/2014 20:54:59.902 75299902
  Taxi    3605    931 15603   4       17/09/2014 20:54:59.902 75299902
  Bus 3563    488 15604   9       17/09/2014 20:54:59.900 75299902
  Taxi    4942    57  15624   1       17/09/2014 20:54:59.900 75299902
  Taxi    784 47  15625   10      17/09/2014 20:54:59.900 75299902
  Taxi    3301    2041    15626   42      17/09/2014 20:54:59.900 75299902
  Bus 2040    2945    15630   27      17/09/2014 20:54:59.900 75299902
  Airplane    2865    2722            0   17/09/2014 20:54:59.900 75299902
  Taxi    4941    51  15624   1        17/09/2014 20:54:59.771    75299771
  Taxi    789 47  15625   10       17/09/2014 20:54:59.771    75299771
  Taxi    3300    2069    15626   42       17/09/2014 20:54:59.771    75299771
  Bus 2027    2947    15630   27       17/09/2014 20:54:59.771    75299771
  Airplane    2865    2722            0    17/09/2014 20:54:59.771    75299771
  </code></pre>
  
  <p>Which functions would work to achieve this result? Thank you on beforehand for your help!</p>