[R] Parsing XML file to data frame

David Winsemius dwinsemius at comcast.net
Tue May 6 17:36:12 CEST 2014


On May 5, 2014, at 11:42 AM, Timothy W. Cook wrote:

> I didn't find an attached XML file. Maybe the list removes attachments?

The list does not remove all attachments, It removes ones that are not among the listed acceptable formats. XML is not among the list of acceptable formats. If it had been submitted as a MIME-text file it would have been accepted.

-- 
David.

> You might try posting to StackOverflow.com if this is the case.
> 
> 
> 
> 
> On Fri, May 2, 2014 at 2:17 PM, starcraz <chan_william at email.com> wrote:
> 
>> 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.
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 
> 
> -- 
> 
> ============================================
> Timothy Cook
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> MLHIM http://www.mlhim.org
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list