title: How do I convert XML to CSV with some missing value in XML file?
body: <p>I have a simple XML data as shown below,</p>
  
  <pre class="lang-py prettyprint-override"><code>&lt;LocationList&gt;
    &lt;Location dateTime="2018-11-17T00:11:01+09:00" x="2711.208" y="566.3292" z="0" motion="Walk" isMoving="True" stepCount="1" groupAreaId="1" commit="True" /&gt;
    &lt;Location dateTime="2018-11-17T00:11:02+09:00" x="2640.506" y="518.7352" z="0" motion="Walk" isMoving="True" stepCount="1" groupAreaId="1" commit="True" /&gt;
    &lt;Location dateTime="2018-11-17T00:11:03+09:00" x="2640.506" y="518.7352" z="0" motion="Stop" isMoving="False" stepCount="0" groupAreaId="1" /&gt;
    &lt;Location dateTime="2018-11-17T00:52:31+09:00" x="2516.404" y="574.0547" z="0" motion="Walk" isMoving="True" stepCount="1" groupAreaId="1" /&gt;
  </code></pre>
  
  <p>and I have tried this to parse the XML into csv file,</p>
  
  <pre class="lang-py prettyprint-override"><code>import xml.etree.ElementTree as et
  import csv
  
  tree = et.parse('./1_2018-11-17.xml')
  nodes = tree.getroot()
  with open('testxml1.csv', 'w') as ff:
      cols = ['dateTime','x','y','z','motion','isMoving','stepCount',
              'groupAreaId','commit']
      nodewriter = csv.writer(ff)
      nodewriter.writerow(cols)
      for node in nodes:
          values = [ node.attrib[kk] for kk in cols]
          nodewriter.writerow(values)
  </code></pre>
  
  <p>However since not all XML lines has the value of 'stepCount', 'groupAreaId', 'commit', the code won't work unless I delete those variables. </p>
  
  <p>How would I be able to get all variables shown in the csv file, including lines with empty value on the variables?</p>