Skip to content
Prev 65777 / 398513 Next

XML to data frame or list

Gabor Grothendieck wrote:

            
For an xml file like this:

<?xml version="1.0"?>
<variables>
<a>100</a>
<b>23</b>
<z>666</z>
</variables>

its a one-liner with the XML package (library(XML)):

xmlReadSimple <-
function(xmlFile){
   as.list(xmlSApply(xmlRoot(xmlTreeParse(xmlFile)),xmlValue))
}

add an lapply(...,as.numeric) for conversion to numbers.

  sweet.

Baz