title: parsing xml in R - return data frame object
body: <p>I have success getting example 1 xml as a dataframe object in R but having trouble with example 2.  Does anyone have suggestions on R code to covert data from mtcars.xml into a dataframe?</p>
  
  <p>example 1)</p>
  
  <pre><code>library(XML)
  # Save the URL of the xml file in a variable
  
  xml.url &lt;- "http://www.w3schools.com/xml/plant_catalog.xml"
  
  # Use the xmlTreePares-function to parse xml file directly from the web
  
  xmlfile &lt;- xmlTreeParse(xml.url)
  
  # Use the xmlRoot-function to access the top node
  xmltop = xmlRoot(xmlfile)
  # have a look at the XML-code of the first subnodes:
  print(xmltop)[1:2]
  
  
  # To extract the XML-values from the document, use xmlSApply:
  
  plantcat &lt;- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue))
  </code></pre>
  
  <p>example2)</p>
  
  <pre><code>    library(XML)
  # Save the URL of the xml file in a variable
  
  doc &lt;- xmlTreeParse(system.file("exampleData", "mtcars.xml", package="XML"))
  
  
  xmlfile &lt;- xmlTreeParse(doc)
  
  # Use the xmlRoot-function to access the top node
  xmltop = xmlRoot(xmlfile)
  # have a look at the XML-code of the first subnodes:
  print(xmltop)[1:2]
  
  
  # To extract the XML-values from the document, use xmlSApply:
  
  mtcarscat &lt;- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue))
  </code></pre>