i have a XML file from which i extracted the paths to the items i want to grep from the XML.
If the provided URL does not work, one may find the XML here: Download XML
Like this:
library(XML)
dat <- read_xml(as.character("http://affi.voetbalshop.nl/google_create_unique.php"))
#dat_list <- dat %>% xml_find_all("//channel//item") %>% as_list()
dat_nodePaths <- dat %>% xml_find_all("//channel//item")
#dat_nodes <- dat %>% xml_find_all("//channel//item")
dat_paths <- xml_path(dat_nodePaths)
Now i want to extract each path one by one and add them to a DataFrame. If i apply it to only one of the paths, i get my DF with only 1 row off course, but it works.
l <- xml_find_first(dat, dat_paths[i]) %>% as_list()
df <- as.data.frame(t(unlist(l)), stringsAsFactors = F)
I have a previous try with xml_find_all() but this gives me less control what to do with each item in my XML.
My current try is this:
df <- rbind(for(i in 1:length(dat_paths)) {
l <- xml_find_first(dat, dat_paths[i]) %>% as_list()
as.data.frame(t(unlist(l)), stringsAsFactors = F)
#df <- rbind(as.data.frame(t(unlist(l))))
})
Tried this with rbind within and outside of the for loop. Within gives me only the last object (obviously). The other only Null.
What can i do to obtain a nicely formatted DataFrame from my XML items?