Похоже, что XML может исходить только от API. имеет пространство имен, так что, вероятно, это вызывает у вас проблемы.Мы просто удалим его.
library(xml2)
xml_ns_strip(
doc <- read_xml("http://contact.woolworths.com.au/storelocator/service/proximity/supermarkets/latitude/-37.7510/longitude/144.8981/range/50/max/200.xml")
) -> doc
data.frame(
name = xml_text(xml_find_all(doc, ".//storeDetail/name")),
lng = xml_double(xml_find_all(doc, ".//storeDetail/longtitude")),
lat = xml_double(xml_find_all(doc, ".//storeDetail/latitude")),
stringsAsFactors = FALSE
) -> stores
str(stores)
## 'data.frame': 188 obs. of 3 variables:
## $ name: chr "Niddrie" "Highpoint West" "Moonee Ponds" "East Keilor" ...
## $ lng : num 145 145 145 145 145 ...
## $ lat : num -37.7 -37.8 -37.8 -37.7 -37.7 ...
Для тех, кто все еще использует XML
?:
library(XML)
doc <- xmlParse("http://contact.woolworths.com.au/storelocator/service/proximity/supermarkets/latitude/-37.7510/longitude/144.8981/range/50/max/200.xml")
def <- c(d = getDefaultNamespace(doc)[[1]]$uri)
data.frame(
name = xpathSApply(doc, "//d:storeDetail/d:name", xmlValue, namespaces = def),
lng = as.numeric(xpathSApply(doc, "//d:storeDetail/d:longtitude", xmlValue, namespaces = def)),
lat = as.numeric(xpathSApply(doc, "//d:storeDetail/d:latitude", xmlValue, namespaces = def)),
stringsAsFactors = FALSE
) -> stores