title: How do I check condition during XML parsing using Python ElementTree
body: <p>I am trying to parse an XML using ElementTree and get all the required fields. </p>
  
  <blockquote>
    <p>Problem :
         My list is getting empty ,    condition that i am trying is- If
        reference('type') == 'cve' then i want to get 'id' text in reference
        tag.</p>
  </blockquote>
  
  <p>Can someone suggest/correct me in getting the required field?</p>
  
  <p>My Actual code is below:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  
  file_name = "updateinfo.xml"
  parser = ET.XMLParser(encoding="utf-8")
  tree = ET.parse(file_name, parser=parser)
  tree_toString = (ET.tostring(tree.getroot()))
  for ele in tree.findall('update'):
      cveList = [
          ele.find('references/reference').get('id') if ele.find('references/reference').get('type') == 'cve' else None
          for cve in ele.find('references/reference')]
      print cveList
  </code></pre>
  
  <p>My XML structure is below :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;updates&gt;
          &lt;update status="final" from="release-engineering@redhat.com" version="4" type="enhancement" &gt;
              &lt;id&gt;RHEA-2017:2259&lt;/id&gt;
              &lt;issued date="2017-08-01 05:59:34 UTC" /&gt;
              &lt;title&gt;new packages: usbguard&lt;/title&gt;
              &lt;release&gt;0&lt;/release&gt;
              &lt;rights&gt;Copyright 2017 Red Hat Inc&lt;/rights&gt;
              &lt;pushcount&gt;4&lt;/pushcount&gt;
              &lt;updated date="2017-08-01 05:59:34 UTC" /&gt;
              &lt;references&gt;
                  &lt;reference href="https://access.redhat.com/errata/RHEA-2017:2259" type="self" id="RHEA-2017:2259" title="RHEA-2017:2259" /&gt;
                  &lt;reference href="https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/7.4_Release_Notes/index.html" type="other" id="ref_0" title="other_reference_0" /&gt;
              &lt;/references&gt;
              &lt;pkglist&gt;
                  &lt;collection short="" &gt;
                      &lt;name&gt;rhel-7-server-rpms__7_DOT_4__x86_64&lt;/name&gt;
                      &lt;package src="usbguard-0.7.0-3.el7.src.rpm" name="usbguard" epoch="0" version="0.7.0" release="3.el7" arch="i686" &gt;
                          &lt;filename&gt;usbguard-0.7.0-3.el7.i686.rpm&lt;/filename&gt;
                          &lt;sum type="sha256" &gt;efd5ca6dd3df02e8537cf45cef48508bf023f568a98ce9f28e9baf77c5caac6c&lt;/sum&gt;
                      &lt;/package&gt;
                      &lt;package src="usbguard-0.7.0-3.el7.src.rpm" name="usbguard" epoch="0" version="0.7.0" release="3.el7" arch="x86_64" &gt;
                          &lt;filename&gt;usbguard-0.7.0-3.el7.x86_64.rpm&lt;/filename&gt;
                          &lt;sum type="sha256" &gt;3f72768880085d6bfff37636d3a8eb54184e5619353b5efbefd5738e74bdfa08&lt;/sum&gt;
                      &lt;/package&gt;
                  &lt;/collection&gt;
              &lt;/pkglist&gt;
          &lt;/update&gt;
          &lt;update status="final" from="security@redhat.com" version="1" type="bugfix" &gt;
              &lt;id&gt;RHBA-2014:0722&lt;/id&gt;
              &lt;issued date="2014-06-10 00:00:00" /&gt;
              &lt;title&gt;kexec-tools bug fix update&lt;/title&gt;
              &lt;rights&gt;Copyright 2014 Red Hat Inc&lt;/rights&gt;
              &lt;pushcount&gt;1&lt;/pushcount&gt;
              &lt;updated date="2014-06-10 00:00:00" /&gt;
              &lt;references&gt;
                  &lt;reference href="https://rhn.redhat.com/errata/RHBA-2014-0722.html" type="self" title="RHBA-2014:0722" /&gt;
              &lt;/references&gt;
              &lt;pkglist&gt;
                  &lt;collection short="" &gt;
                      &lt;name&gt;rhel-7-server-rpms__7_DOT_4__x86_64&lt;/name&gt;
                      &lt;package src="kexec-tools-2.0.4-32.el7_0.1.src.rpm" name="kexec-tools" epoch="0" version="2.0.4" release="32.el7_0.1" arch="x86_64" &gt;
                          &lt;filename&gt;kexec-tools-2.0.4-32.el7_0.1.x86_64.rpm&lt;/filename&gt;
                          &lt;sum type="sha256" &gt;8e214681104e4ba73726e0ce11d21b963ec0390fd70458d439ddc72372082034&lt;/sum&gt;
                      &lt;/package&gt;
                  &lt;/collection&gt;
              &lt;/pkglist&gt;
          &lt;/update&gt;
          &lt;update status="final" from="release-engineering@redhat.com" version="4" type="security" &gt;
              &lt;id&gt;RHSA-2017:2831&lt;/id&gt;
              &lt;issued date="2017-09-28 18:56:55 UTC" /&gt;
              &lt;title&gt;Critical: firefox security update&lt;/title&gt;
              &lt;release&gt;0&lt;/release&gt;
              &lt;rights&gt;Copyright 2017 Red Hat Inc&lt;/rights&gt;
              &lt;severity&gt;Critical&lt;/severity&gt;
              &lt;pushcount&gt;4&lt;/pushcount&gt;
              &lt;updated date="2017-09-28 18:56:56 UTC" /&gt;
              &lt;references&gt;
                  &lt;reference href="https://access.redhat.com/errata/RHSA-2017:2831" type="self" id="RHSA-2017:2831" title="RHSA-2017:2831" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496649" type="bugzilla" id="1496649" title="CVE-2017-7793 Mozilla: Use-after-free with Fetch API (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496651" type="bugzilla" id="1496651" title="CVE-2017-7810 Mozilla: Memory safety bugs fixed in Firefox 56 and Firefox ESR 52.4 (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496652" type="bugzilla" id="1496652" title="CVE-2017-7814 Mozilla: Blob and data URLs bypass phishing and malware protection warnings (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496653" type="bugzilla" id="1496653" title="CVE-2017-7818 Mozilla: Use-after-free during ARIA array manipulation (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496654" type="bugzilla" id="1496654" title="CVE-2017-7819 Mozilla: Use-after-free while resizing images in design mode (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496655" type="bugzilla" id="1496655" title="CVE-2017-7823 Mozilla: CSP sandbox directive did not create a unique origin (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1496656" type="bugzilla" id="1496656" title="CVE-2017-7824 Mozilla: Buffer overflow when drawing and validating elements with ANGLE (MFSA 2017-22)" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7793.html" type="cve" id="CVE-2017-7793" title="CVE-2017-7793" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7810.html" type="cve" id="CVE-2017-7810" title="CVE-2017-7810" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7814.html" type="cve" id="CVE-2017-7814" title="CVE-2017-7814" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7818.html" type="cve" id="CVE-2017-7818" title="CVE-2017-7818" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7819.html" type="cve" id="CVE-2017-7819" title="CVE-2017-7819" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7823.html" type="cve" id="CVE-2017-7823" title="CVE-2017-7823" /&gt;
                  &lt;reference href="https://www.redhat.com/security/data/cve/CVE-2017-7824.html" type="cve" id="CVE-2017-7824" title="CVE-2017-7824" /&gt;
                  &lt;reference href="https://access.redhat.com/security/updates/classification/#critical" type="other" id="classification" title="critical" /&gt;
                  &lt;reference href="https://www.mozilla.org/en-US/security/advisories/mfsa2017-22/" type="other" id="ref_0" title="other_reference_0" /&gt;
              &lt;/references&gt;
              &lt;pkglist&gt;
                  &lt;collection short="" &gt;
                      &lt;name&gt;rhel-7-server-rpms__7_DOT_4__x86_64&lt;/name&gt;
                      &lt;package src="firefox-52.4.0-1.el7_4.src.rpm" name="firefox" epoch="0" version="52.4.0" release="1.el7_4" arch="x86_64" &gt;
                          &lt;filename&gt;firefox-52.4.0-1.el7_4.x86_64.rpm&lt;/filename&gt;
                          &lt;sum type="sha256" &gt;7b81b37bf969534bee0152bc13db56ae410eee06120a78d8da261c10c73c0514&lt;/sum&gt;
                      &lt;/package&gt;
                  &lt;/collection&gt;
              &lt;/pkglist&gt;
          &lt;/update&gt;
          &lt;update status="final" from="release-engineering@redhat.com" version="2" type="bugfix" &gt;
              &lt;id&gt;RHBA-2016:2423&lt;/id&gt;
              &lt;issued date="2016-11-03 06:09:21 UTC" /&gt;
              &lt;title&gt;oscap-anaconda-addon bug fix update&lt;/title&gt;
              &lt;release&gt;0&lt;/release&gt;
              &lt;rights&gt;Copyright 2016 Red Hat Inc&lt;/rights&gt;
              &lt;severity&gt;None&lt;/severity&gt;
              &lt;pushcount&gt;2&lt;/pushcount&gt;
              &lt;updated date="2016-11-03 06:10:44 UTC" /&gt;
              &lt;references&gt;
                  &lt;reference href="https://access.redhat.com/errata/RHBA-2016:2423" type="self" id="RHBA-2016:2423" title="RHBA-2016:2423" /&gt;
                  &lt;reference href="https://bugzilla.redhat.com/show_bug.cgi?id=1269211" type="bugzilla" id="1269211" title="could move security section down to bottom since it's not as important as network spoke" /&gt;
              &lt;/references&gt;
              &lt;pkglist&gt;
                  &lt;collection short="" &gt;
                      &lt;name&gt;rhel-7-server-rpms__7_DOT_4__x86_64&lt;/name&gt;
                      &lt;package src="oscap-anaconda-addon-0.7-12.el7.src.rpm" name="oscap-anaconda-addon" epoch="0" version="0.7" release="12.el7" arch="noarch" &gt;
                          &lt;filename&gt;oscap-anaconda-addon-0.7-12.el7.noarch.rpm&lt;/filename&gt;
                          &lt;sum type="sha256" &gt;507fbf46ddaed0bb4087d3ef2b31db235473f3be36aaa9ed7df43279ed7e2f07&lt;/sum&gt;
                      &lt;/package&gt;
                  &lt;/collection&gt;
              &lt;/pkglist&gt;
          &lt;/update&gt;
  </code></pre>