I have been using the following script which worked well for many years but an update of the XML package in R I think rendered what I had to only partially work.
download.file("http://forecast.weather.gov/MapClick.php?lat=47.9733&lon=-121.6413&FcstType=digitalDWML","temp.xml") #This is for the lake surface
data1 <- xmlParse("temp.xml")
temp_path <- "//temperature[@type='hourly']/value"
precip_path <- "//hourly-qpf[@type='floating']/value"
df1 <- data.frame(
latitude=data1[["number(//point/@latitude)"]],
longitude=data1[["number(//point/@longitude)"]],
hourly_temperature=as.integer(sapply(data1[temp_path], as, "integer"))
hourly_precip=as.numeric(sapply(data1[precip_path],as,"double"))
)
df1$date1<- seq(Sys.time(), by="hour", length.out = length(df1$hourly_temperature))
The hourly temperature part parses correctly but the precipitation part does not parse correctly anymore. I have tried a number of different options but apparently I am bad with XML. Any help would be really appreciated!