I want to extract both 'lat' and 'long' from a .xml file like this:
<asdf>
<dataset>
<px lon="-55.75" lat="-18.5">2.186213</px>
<px lon="-50.0" lat="-18.5">0.0</px>
<px lon="-66.75" lat="-03.0">1.68412</px>
</dataset>
</asdf>
this is what I've done so far, using the R::XML package:
#Load library for xml loading reading extracting
library(XML)
#Parse xml file
a3 <- xmlRoot(xmlTreeParse("my_file.xml"))
#Extract text-value and attributes as lists
precip <- xmlSApply(a3, function(x) xmlSApply(x, xmlValue))
long <- xmlSApply(a3, function(x) xmlSApply(x, xmlAttrs))
lat <- xmlSApply(a3, function(x) xmlSApply(x, xmlAttrs)) #???
dt.lat.long.val <- data.frame(as.numeric(as.vector(lat)),
as.numeric(as.vector(long)),
as.numeric(as.vector(precip)))
How do I edit the line ending in #??? so to get the lat values?