title: Python xml read if have tag value using xml.etree.ElementTree
body: <p>I'm trying to read this file if  &quot;TypeOfVessel&quot; value is not null.  list will be read if have &quot;TypeOfVessel&quot; value. Please see my code below. any suggestion please. Thanks</p>
  <pre><code>&lt;ArrayOfConsolidatedList xmlns:i=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://schemas.datacontract.org/2004/07/&quot;&gt;
      &lt;ConsolidatedList&gt;
          &lt;RegimeName&gt;Test1&lt;/RegimeName&gt;
          &lt;Subsidiaries i:nil=&quot;true&quot; /&gt;
          &lt;TonnageOfVessel i:nil=&quot;true&quot; /&gt;
          &lt;TownOfBirth i:nil=&quot;true&quot; /&gt;
          &lt;TypeOfVessel i:nil=&quot;true&quot; /&gt;
      &lt;/ConsolidatedList&gt;
      &lt;ConsolidatedList&gt;
          &lt;RegimeName&gt;Test2&lt;/RegimeName&gt;
          &lt;Subsidiaries i:nil=&quot;true&quot;/&gt;
          &lt;TonnageOfVessel&gt;841&lt;/TonnageOfVessel&gt;
          &lt;TownOfBirth i:nil=&quot;true&quot;/&gt;
          &lt;TypeOfVessel&gt;Bunkering Vessel&lt;/TypeOfVessel&gt;
      &lt;/ConsolidatedList&gt;
  &lt;/ArrayOfConsolidatedList&gt;
  </code></pre>
  <p>Python code:</p>
  <pre><code>import xml.etree.ElementTree as ET
  import inspect
  
  def ListParse():
      tree = ET.parse('ListRead.xml')
      root = tree.getroot()
      all_entity_entries = root.find(&quot;{http://schemas.datacontract.org/2004/07/}ArrayOfConsolidatedList&quot;)
      for entry in all_entity_entries:                                                
          RegimeName = entry.find('RegimeName').text
          TonnageOfVessel = entry.find('TonnageOfVessel')
          TypeOfVessel = entry.find('TypeOfVessel')
          print(TypeOfVessel)
              
  ListParse()
  </code></pre>