I have many XML objects of the following format:
<GetSingleItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2012-10-25T03:09:50.817Z</Timestamp>
<Ack>Success</Ack>
<Build>E795_CORE_BUNDLED_15430047_R1</Build>
<Version>795</Version>
<Item>
<Description>...</Description>
<ItemID>330810813385</ItemID>
<EndTime>2012-10-25T04:32:37.000Z</EndTime>
<Location>Paypal Prefered</Location>
<GalleryURL>...</GalleryURL>
<PictureURL>...</PictureURL>
<PictureURL>...</PictureURL>
<PrimaryCategoryID>177</PrimaryCategoryID>
<PrimaryCategoryName>
Computers/Tablets & Networking:Laptops & Netbooks:PC Laptops & Netbooks
</PrimaryCategoryName>
<BidCount>2</BidCount>
<ConvertedCurrentPrice currencyID="USD">294.99</ConvertedCurrentPrice>
<ListingStatus>Active</ListingStatus>
<TimeLeft>PT1H22M47S</TimeLeft>
<Title>
HP Compaq ZD8000 3800Mhz Full Loaded Ready to go, nice unit & super fast Laptop
</Title>
<ShippingCostSummary>
<ShippingServiceCost currencyID="USD">23.99</ShippingServiceCost>
<ShippingType>Flat</ShippingType>
<ListedShippingServiceCost currencyID="USD">23.99</ListedShippingServiceCost>
</ShippingCostSummary>
<ItemSpecifics>
<NameValueList>
<Name>Operating System</Name>
<Value>Windows XP Professional</Value>
</NameValueList>
<NameValueList>
<Name>Screen Size</Name>
<Value>17.0</Value>
</NameValueList>
<NameValueList>
<Name>Processor Type</Name>
<Value>Intel Pentium 4 HT</Value>
</NameValueList>
</ItemSpecifics>
<Country>US</Country>
<AutoPay>false</AutoPay>
<ConditionID>2500</ConditionID>
<ConditionDisplayName>Seller refurbished</ConditionDisplayName>
</Item>
</GetSingleItemResponse>
For each xml object I'd like to obtain all the item tag tags, such as itemid, endtime, etc.. and also all the item specifics tag tags, such as Operating System, Screen Size, etc. I'd like to save this into memory for each xml object into an appropriate data structure (object). Finally, I'd like to write all the information for all the xml objects into a csv file.
The difficulty is that a priori I do NOT know know what the columns (header) for the csv file will be. For the first xml object I'd create as many columns as the number of subtags the item and item specifics combined have.
Then I'd add more and more columns as new columns appear for new items, adding NAs for the columns that haven't appeared before.
I am looking for advice on how to process the xml objects, which data structures to convert (save) the xml objects, and also how to write all the finally processed xml data into a csv file.
Thanks.