Skip to content
Prev 65829 / 398513 Next

XML to data frame or list

I managed to parse more complex XML files as well. The trick was to
manually determine the position of the child nodes of interest, after
which they can be parsed in a loop. For example:

require(XML)
doc <- xmlTreeParse("file.xml",getDTD=T,addAttributeNamespaces=T)
r <- xmlRoot(doc)

#find the nodes of interest
r[[i]][[j]]....

#then read them
xmldata <- list(NULL)
for (i in 1:xmlSize(r[[2]][[1]])) {
  xmldata[[i]] <- as.data.frame(xmlSApply(r[[2]][[1]][[i]],xmlValue))
  }
--- Barry Rowlingson <B.Rowlingson at lancaster.ac.uk> wrote: