I'm trying to convert a XML with a complex structure of nodes into a data frame using R. This is a brief example of the XML file:
<products>
<product>
<id>1</id>
<data>
<data_value>
<number>12345</number>
<city>London</city>
</data_value>
</data>
<attributes>
<p_attribute>
<name>Name_1</name>
<value>Value_1</value>
</p_attribute>
<p_attribute>
<name>Name_2</name>
<value>Value_2</value>
</p_attribute>
</attributes>
</product>
<product>
<id>2</id>
<data>
<data_value>
<number>98765</number>
<city>London</city>
</data_value>
</data>
<attributes>
<p_attribute>
<name>Name_9</name>
<value>Value_9</value>
</p_attribute>
<p_attribute>
<name>Name_8</name>
<value>Value_8</value>
</p_attribute>
</attributes>
</product>
</products>
When I try to convert this file to a data frame, I use the following code (XML library)
library(XML)
doc=xmlParse("file.xml")
xmldf=xmlToDataFrame(nodes = getNodeSet(doc, "//product"))
And after that, the final result is this data frame that you can see bellow:
id data attributes
1 1 12345London Name_1Value_1Name_2Value_2
2 2 98765London Name_9Value_9Name_8Value_8
How can I get a different data frame, eliminating the complex structure of the XML file to get a result like this?
id number city name.1 value.1 name.2 value.2
1 1 12345 London Name_1 Value_1 Name_2 Vlaue_2
2 2 98765 London Name_9 Value_9 Name_8 Value_8