title: XML to CSV in PYTHON: Extract series of subnodes for every node
body: <p>My goal is to convert an .XML file into a .CSV file.
  This part of the code is already functional.</p>
  
  <p>However, I also want to extract the sub-sub-nodes of one of the "father" nodes.</p>
  
  <p>Maybe an example would be more self explanatory;</p>
  
  <p>Here is the structure of my XML:</p>
  
  <pre><code>&lt;nedisCatalogue&gt;
     &lt;headerInfo&gt;
      &lt;feedVersion&gt;1-0&lt;/feedVersion&gt;
      &lt;dateCreated&gt;2018-01-22T23:37:01+0100&lt;/dateCreated&gt;
      &lt;supplier&gt;Nedis_BENED&lt;/supplier&gt;
      &lt;locale&gt;nl_BE&lt;/locale&gt;
     &lt;/headerInfo&gt;
     &lt;productList&gt;
      &lt;product&gt;
       &lt;nedisPartnr&gt;&lt;![CDATA[VS-150/63BA]]&gt;&lt;/nedisPartnr&gt;
       &lt;nedisArtlid&gt;17005&lt;/nedisArtlid&gt;
       &lt;vendorPartnr&gt;&lt;![CDATA[TONFREQ-ELKOS / BIPOL 150, 5390]]&gt;&lt;/vendorPartnr&gt;
       &lt;brand&gt;&lt;![CDATA[Visaton]]&gt;&lt;/brand&gt;
       &lt;EAN&gt;4007540053905&lt;/EAN&gt;
       &lt;intrastatCode&gt;8532220000&lt;/intrastatCode&gt;
       &lt;UNSPSC&gt;52161514&lt;/UNSPSC&gt;
       &lt;headerText&gt;&lt;![CDATA[Crossover Foil capacitor]]&gt;&lt;/headerText&gt;
       &lt;internetText&gt;&lt;![CDATA[Bipolaire elco met een ruwe folie en een zeer goede prijs/kwaliteits-verhouding voor de bouw van cross-overs. 63 Vdc, 10% tolerantie.]]&gt;&lt;/internetText&gt;
       &lt;generalText&gt;&lt;![CDATA[Dimensions 16 x 35 mm    
      ]]&gt;&lt;/generalText&gt;
    &lt;images&gt;
     &lt;image type="2" order="15"&gt;767736.JPG&lt;/image&gt;
    &lt;/images&gt;
    &lt;attachments&gt;
    &lt;/attachments&gt;
    &lt;categories&gt;
     &lt;tree name="Internet_Tree_ISHP"&gt;
      &lt;entry depth="001" id="1067858"&gt;&lt;![CDATA[Audio]]&gt;&lt;/entry&gt;
      &lt;entry depth="002" id="1067945"&gt;&lt;![CDATA[Speakers]]&gt;&lt;/entry&gt;
      &lt;entry depth="003" id="1068470"&gt;&lt;![CDATA[Accessoires]]&gt;&lt;/entry&gt;
     &lt;/tree&gt;
    &lt;/categories&gt;
    &lt;properties&gt;
     &lt;property id="360" multiplierID="" unitID="" valueID=""&gt;&lt;![CDATA[...]]&gt;&lt;/property&gt;
    &lt;/properties&gt;
       &lt;status&gt;
        &lt;code status="NORMAL"&gt;&lt;/code&gt;
       &lt;/status&gt;
       &lt;packaging quantity="1" weight="8"&gt;&lt;/packaging&gt;
       &lt;introductionDate&gt;2015-10-26&lt;/introductionDate&gt;
       &lt;serialnumberKeeping&gt;N&lt;/serialnumberKeeping&gt;
       &lt;priceLevels&gt;
            &lt;normalPricing from="2017-02-13" to="2018-01-23"&gt;
         &lt;price level="1" moq="1" currency="EUR"&gt;2.48&lt;/price&gt;
        &lt;/normalPricing&gt;
        &lt;specialOfferPricing&gt;&lt;/specialOfferPricing&gt;
       &lt;goingPriceInclVAT currency="EUR" quantity="1"&gt;3.99&lt;/goingPriceInclVAT&gt;
       &lt;/priceLevels&gt;
       &lt;tax&gt;
       &lt;/tax&gt;
       &lt;stock&gt;
        &lt;inStockLocal&gt;25&lt;/inStockLocal&gt;
        &lt;inStockCentral&gt;25&lt;/inStockCentral&gt;
        &lt;ATP&gt;
         &lt;nextExpectedStockDateLocal&gt;&lt;/nextExpectedStockDateLocal&gt;
         &lt;nextExpectedStockDateCentral&gt;&lt;/nextExpectedStockDateCentral&gt;
        &lt;/ATP&gt;
       &lt;/stock&gt;
      &lt;/product&gt;
    ....
  &lt;/nedisCatalogue&gt;
  </code></pre>
  
  <p>And here is the code that I have now:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import csv
  
  tree = ET.parse("/Users/BE07861/Documents/nedis_catalog_2018-01-23_nl_BE_32191_v1-0_xml")
  root = tree.getroot()
  
  f = open('/Users/BE07861/Documents/test2.csv', 'w')
  
  csvwriter = csv.writer(f, delimiter='ç')
  
  count = 0
  
  head = ['Nedis Part Number', 'Nedis Article ID', 'Vendor Part Number', 'Brand', 'EAN', 'Header text', 'Internet Text', 'General Text', 'categories']
  prdlist = root[1]
  prdct = prdlist[5]
  cat = prdct[12]
  tree1=cat[0]
  
  csvwriter.writerow(head)
  
  for time in prdlist.findall('product'):
      row = []
      nedis_number = time.find('nedisPartnr').text
      row.append(nedis_number)
      nedis_art_id = time.find('nedisArtlid').text
      row.append(nedis_art_id)
      vendor_part_nbr = time.find('vendorPartnr').text
      row.append(vendor_part_nbr)
      Brand = time.find('brand').text
      row.append(Brand)
      ean = time.find('EAN').text
      row.append(ean)
      header_text = time.find('headerText').text
      row.append(header_text)
      internet_text = time.find('internetText').text
      row.append(internet_text)
      general_text = time.find('generalText').text
      row.append(general_text)
      categ = time.find('categories').find('tree').find('entry').text
      row.append(categ)
      csvwriter.writerow(row)
  
  f.close()
  </code></pre>
  
  <p>If you run the code, you'll see that I only retrieve the first "entry" of the categories/tree; which is normal. However, I don't know how to create a loop that, for every node "categories", creates new columns such as categories1, categories2 &amp; categories3 with the values: "entry".</p>
  
  <p>My result should look like this</p>
  
  <pre><code>Nedis Part Number   Nedis Article ID         Vendor Part Number   
  VS-150/63BA         17005              TONFREQ-ELKOS / BIPOL 150, 5390  
  
  
  Brand     EAN           Header text               Internet Text 
  Visaton   4,00754E+12   Crossover Foil capacitor  Bipolaire elco …
  
  
  
  General Text              Category1    Categroy2     Category3
  Dimensions 16 x 35 mm     Audio        Speakers      Accessoires
  </code></pre>
  
  <p>I've really tried my best but didn't manage to find the solution.</p>
  
  <p>Any help would be very much appreciated!!! :)</p>
  
  <p>Thanks a lot,</p>
  
  <p>Allan</p>