title: parse many xml objects and write them into a text file (csv, tab-del, ...) using python
body: <p>I have many XML objects of the following format:</p>
  
  <pre><code>&lt;GetSingleItemResponse xmlns="urn:ebay:apis:eBLBaseComponents"&gt;
    &lt;Timestamp&gt;2012-10-25T03:09:50.817Z&lt;/Timestamp&gt;
    &lt;Ack&gt;Success&lt;/Ack&gt;
    &lt;Build&gt;E795_CORE_BUNDLED_15430047_R1&lt;/Build&gt;
    &lt;Version&gt;795&lt;/Version&gt;
    &lt;Item&gt;
       &lt;Description&gt;...&lt;/Description&gt;
       &lt;ItemID&gt;330810813385&lt;/ItemID&gt;
       &lt;EndTime&gt;2012-10-25T04:32:37.000Z&lt;/EndTime&gt;
       &lt;Location&gt;Paypal Prefered&lt;/Location&gt;
       &lt;GalleryURL&gt;...&lt;/GalleryURL&gt;
       &lt;PictureURL&gt;...&lt;/PictureURL&gt;
       &lt;PictureURL&gt;...&lt;/PictureURL&gt;
       &lt;PrimaryCategoryID&gt;177&lt;/PrimaryCategoryID&gt;
       &lt;PrimaryCategoryName&gt;
       Computers/Tablets &amp; Networking:Laptops &amp; Netbooks:PC Laptops &amp; Netbooks
       &lt;/PrimaryCategoryName&gt;
       &lt;BidCount&gt;2&lt;/BidCount&gt;
       &lt;ConvertedCurrentPrice currencyID="USD"&gt;294.99&lt;/ConvertedCurrentPrice&gt;
       &lt;ListingStatus&gt;Active&lt;/ListingStatus&gt;
       &lt;TimeLeft&gt;PT1H22M47S&lt;/TimeLeft&gt;
       &lt;Title&gt;
       HP Compaq ZD8000 3800Mhz Full Loaded Ready to go, nice unit &amp; super fast Laptop
       &lt;/Title&gt;
       &lt;ShippingCostSummary&gt;
       &lt;ShippingServiceCost currencyID="USD"&gt;23.99&lt;/ShippingServiceCost&gt;
       &lt;ShippingType&gt;Flat&lt;/ShippingType&gt;
       &lt;ListedShippingServiceCost currencyID="USD"&gt;23.99&lt;/ListedShippingServiceCost&gt;
       &lt;/ShippingCostSummary&gt;
       &lt;ItemSpecifics&gt;
          &lt;NameValueList&gt;
             &lt;Name&gt;Operating System&lt;/Name&gt;
             &lt;Value&gt;Windows XP Professional&lt;/Value&gt;
          &lt;/NameValueList&gt;
          &lt;NameValueList&gt;
             &lt;Name&gt;Screen Size&lt;/Name&gt;
             &lt;Value&gt;17.0&lt;/Value&gt;
          &lt;/NameValueList&gt;
          &lt;NameValueList&gt;
             &lt;Name&gt;Processor Type&lt;/Name&gt;
             &lt;Value&gt;Intel Pentium 4 HT&lt;/Value&gt;
          &lt;/NameValueList&gt;
       &lt;/ItemSpecifics&gt;
       &lt;Country&gt;US&lt;/Country&gt;
       &lt;AutoPay&gt;false&lt;/AutoPay&gt;
       &lt;ConditionID&gt;2500&lt;/ConditionID&gt;
       &lt;ConditionDisplayName&gt;Seller refurbished&lt;/ConditionDisplayName&gt;
     &lt;/Item&gt;
  &lt;/GetSingleItemResponse&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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.  </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thanks.</p>