I wrote the below code to parse a simple XML file.
xmlfile <- xmlTreeParse(inFile$datapath,encoding = "UTF-8")
xmltop = xmlRoot(xmlfile)
singlexml <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue))
singlexml_df <- as.data.frame(t(singlexml),row.names=NULL)
indx <- sapply(singlexml_df, is.list)
singlexml_df[indx] <- lapply(singlexml_df[indx], function(x) as.character(x))
singlexml_df
XML :
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<PLANT>
<COMMON>Bloodroot</COMMON>
<BOTANICAL>Sanguinaria canadensis</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.44</PRICE>
<AVAILABILITY>031599</AVAILABILITY>
</PLANT>
<PLANT>
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.37</PRICE>
<AVAILABILITY>030699</AVAILABILITY>
</PLANT>
</CATALOG>
And it is successfully parsed and got converted to a dataframe.
But my new requirement is to parse a nested XML.
When I am trying to parse new nested XML everything is getting combined in a single column and not correctly getting transformed to a data frame.
I want Please provide your suggestions.
Thanks