[R] Assistance converting to R a python function that extracts from an XML file
Duncan Temple Lang
dtemplelang at ucdavis.edu
Sat Dec 13 22:06:02 CET 2014
Hi Don
library(XML)
readxmldate =
function(xmlfile)
{
doc = xmlParse(xmlfile)
xpathSApply(doc, '//Esri/CreaDate | //Esri/CreaTime', xmlValue)
}
D.
On 12/13/14, 12:36 PM, MacQueen, Don wrote:
> I would appreciate assistance doing in R what a colleague has done in
> python. Unfortunately (for me), I have almost no experience with either
> python or xml.
>
> Within an xml file there is
> <CreaDate>20120627</CreaDate><CreaTime>07322600</CreaTime>
> and I need to extract those two values, 20120627 and 07322600
>
>
> Here is the short python function. Even without knowing python, it's
> conceptually clear what it does. I would like to do the same in R.
>
> def readxmldate(xmlfile):
> tree = ET.parse(xmlfile)
> root = tree.getroot()
> for lev1 in root.findall('Esri'):
> xdate = lev1.find('CreaDate').text
> xtime = lev1.find('CreaTime').text
> return xdate, xtime
>
>
> Thanks in advance
> -Don
>
More information about the R-help
mailing list