Message-ID: <4231B3EA.90708@lancaster.ac.uk>
Date: 2005-03-11T15:06:18Z
From: Barry Rowlingson
Subject: XML to data frame or list
In-Reply-To: <loom.20050311T154207-618@post.gmane.org>
Gabor Grothendieck wrote:
>
> You could check out the ctv package that was recently announced.
> It uses XML so its source would provide an example.
>
> If its a one-time operation, Excel reads XML and you could then
> use one of the many Excel to R possibilities.
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