Re: [R] XML to data frame or list

From: bogdan romocea <br44114_at_yahoo.com>
Date: Mon 14 Mar 2005 - 00:58:40 EST


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))   }

> http://mail.yahoo.com

>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Mar 14 12:46:59 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:47 EST