Skip to content

XML to data frame or list

1 message · bogdan romocea

#
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: