Skip to content
Prev 315894 / 398513 Next

Create a Data Frame from an XML

Hi Adam

 [You seem to have sent the same message twice to the mailing list.]

There are various strategies/approaches to creating the data frame
from the XML.

Perhaps the approach that most closely follows your approach is

  xmlRoot(doc)[ "row" ]

which  returns a list of XML nodes whose node name is "row" that are
children of the root node <data>.

So
  sapply(xmlRoot(doc) [ "row" ], xmlAttrs)

yields a matrix with as many columns as there are  <row> nodes
and with 3 rows - one for each of the BRAND, YEAR and VALUE attributes.

So

  d = t( sapply(xmlRoot(doc) [ "row" ], xmlAttrs) )

gives you a matrix with the correct rows and column orientation
and now you can turn that into a data frame, converting the
columns into numbers, etc. as you want with regular R commands
(i.e. independently of the XML).


 D.
On 1/22/13 1:43 PM, Adam Gabbert wrote: