[R] Parsing XML file to data frame

starcraz chan_william at email.com
Fri May 2 19:17:20 CEST 2014


Hi all - I am trying to parse out the attached XML file into a data frame.
The file is extracted from Hadoop File Services (HFS). I am new in using the
XML package so need some help in parsing out the data. Below is some code
that I explore to get the attribute into a data frame. Any help is
appreciated.

library(XML)
temp <- xmlParseDoc("sample.xml")
temp.root <- xmlRoot(temp)
xmlName(temp.root)
xmlSize(temp.root) #21 child nodes
temp.root[[2]] #headers
temp.root[[2]][[2]] #extracts just the revision
temp.2 <- xmlToList(temp.root[[2]]) #extracts the info in temp.root[[2]]
into a list
temp.2
temp.2.df <- xmlToDataFrame(temp.root[[2]]) #data frame of the list
temp.2.df
xmlValue(temp.root[[2]]) #string the values of the node inside [[2]]

temp.revision <- xmlValue(temp.root[[2]][["Revision"]])
temp.revision

test <- xmlTreeParse("sample.xml")
test




--
View this message in context: http://r.789695.n4.nabble.com/Parsing-XML-file-to-data-frame-tp4689883.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list