title: Parse XML and write to a large CSV file
body: <p>How can I efficiently parse a large XML file (4 GB) and write rows in CSV?
  Now, I'm using <code>lxml</code> and <code>csv.</code></p>
  <pre><code>xmltree = etree.parse(&quot;my.xml&quot;)
  xmlroot = xmltree.getroot()
  with open(file_name, 'w') as file:
      writer = csv.writer(file, delimiter=&quot;,&quot;)
      for tag in xmlroot.findall('*'):
          csv_row = []
          for attribute in attribute_list:
              attribute_value = None
              if tag.findall(my_list):
                  attribute_value = tag.find(attribute).text
                  csv_row.append(attribute_value)
          writer.writerow(csv_row)
           
  </code></pre>