Import all fields (and subfields) of XML as dataframe

Replace

New Member
To do some analysis I want to import a XML to a dataframe using R and the XML package. Example of XML file:\[code\]<watchers shop_name="TEST" created_at="September 14, 2012 05:44"><watcher channel="Site Name"> <code>123456</code> <search_key>TestKey</search_key> <date>September 14, 2012 04:15</date> <result>Found</result> <link>http://www.test.com/fakeurl</link> <price>100.0</price> <shipping>0.0</shipping> <position>0</position> <name>Name Test</name> <results> <result position="1"> <c_name>CTest1</c_name> <c_price>599.49</c_price> <c_shipping>0.0</c_shipping> <c_total_price>599.49</c_total_price> <c_rating>8.3</c_rating> <c_delivery/> </result><result position="2"> <c_name>CTest2</c_name> <c_price>654.0</c_price> <c_shipping>0.0</c_shipping> <c_total_price>654.0</c_total_price> <c_rating>9.8</c_rating> <c_delivery/> </result> <result position="3"> <c_name>CTest3</c_name> <c_price>654.0</c_price> <c_shipping>0.0</c_shipping> <c_total_price>654.0</c_total_price> <c_rating>8.8</c_rating> <c_delivery/> </result> </results></watcher>\[/code\]I want to have the rows of the dataframe containing the following fields:\[code\]shop_name created_at code search_key date resultlink price shipping position name position c_name c_price c_shipping c_total_price c_rating c_delivery\[/code\]This means that the child nodes must be taken into account as well, which would result in a dataframe of three rows in this example (since the results show 3 positions). The fields\[code\]shop_name created_at code search_keydate result link price shipping position name position\[/code\]are the same for each of these rows. I am able to go through the XML file, but I am unable to get a dataframe with the fields i want. When I convert the dataframe to a dataframe I get the following fields:\[code\]"code" "search_key" "date" "result" "link" "price" "shipping" "position" "name" "results" \[/code\]Here the fields \[code\]shop_name created_at\[/code\]are missing at the beginning and the results are put together in a String under the column "results". It must be possible to get the wanted dataframe, but I do not know how to do this exactly.
 
Back
Top