title: Python ElementTree filter categories within children xml list with findall
body: <p>I would like to work with the <a href="https://data.europa.eu/euodp/en/data/dataset/transparency-register" rel="nofollow noreferrer">European Transparancy Register</a> with Python, however, I had some troubles so far. Below you will find a very simplified version of the XML (which normally contains 1.6 million lines).</p>
  <p>I would like to retrieve all the companies that have ticked the category <code>Digital economy and society</code> in their <code>interests</code>.</p>
  <p>However, I am having great difficulty using the <code>findall()</code> of <code>ElementTree</code> with this very particular XML structure. You can find below an excerpt of my code with the first results I was able to obtain. The filter returns nothing.</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;ListOfIRPublicDetail xmlns:ns2=&quot;http://www.w3.org/1999/xlink&quot; xmlns=&quot;http://intragate.ec.europa.eu/transparencyregister/intws/20200626&quot;&gt;
    &lt;metaData&gt;
      &lt;exportDate&gt;2021-01-21T12:20:00.122+01:00&lt;/exportDate&gt;
      &lt;numberOfIR&gt;12205&lt;/numberOfIR&gt;
    &lt;/metaData&gt;
    &lt;resultList&gt;
      &lt;interestRepresentative&gt;
        &lt;name&gt;
          &lt;originalName&gt;F. Hoffmann-La Roche Ltd&lt;/originalName&gt;
        &lt;/name&gt;
        &lt;interests&gt;
          &lt;interest index=&quot;1&quot;&gt;
            &lt;name&gt;Budget&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;2&quot;&gt;
            &lt;name&gt;Business and Industry&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;3&quot;&gt;
            &lt;name&gt;Climate Action&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;4&quot;&gt;
            &lt;name&gt;Competition&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;5&quot;&gt;
            &lt;name&gt;Consumers&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;6&quot;&gt;
            &lt;name&gt;Digital economy and society&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;7&quot;&gt;
            &lt;name&gt;Economy, finance and the euro&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;8&quot;&gt;
            &lt;name&gt;Environment&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;9&quot;&gt;
            &lt;name&gt;External Relations&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;10&quot;&gt;
            &lt;name&gt;Institutional affairs&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;11&quot;&gt;
            &lt;name&gt;International co-operation and development&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;12&quot;&gt;
            &lt;name&gt;Justice and Fundamental Rights&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;13&quot;&gt;
            &lt;name&gt;Public Health&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;14&quot;&gt;
            &lt;name&gt;Research and innovation&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;15&quot;&gt;
            &lt;name&gt;Single market&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;16&quot;&gt;
            &lt;name&gt;Trade&lt;/name&gt;
          &lt;/interest&gt;
        &lt;/interests&gt;
      &lt;/interestRepresentative&gt;
      &lt;interestRepresentative&gt;
        &lt;name&gt;
          &lt;originalName&gt;Nickel Institute&lt;/originalName&gt;
        &lt;/name&gt;
        &lt;interests&gt;
          &lt;interest index=&quot;1&quot;&gt;
            &lt;name&gt;Business and Industry&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;2&quot;&gt;
            &lt;name&gt;Climate Action&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;3&quot;&gt;
            &lt;name&gt;Consumers&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;4&quot;&gt;
            &lt;name&gt;Economy, finance and the euro&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;5&quot;&gt;
            &lt;name&gt;Employment and Social Affairs&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;6&quot;&gt;
            &lt;name&gt;Energy&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;7&quot;&gt;
            &lt;name&gt;Environment&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;8&quot;&gt;
            &lt;name&gt;Food Safety&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;9&quot;&gt;
            &lt;name&gt;Public Health&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;10&quot;&gt;
            &lt;name&gt;Research and innovation&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;11&quot;&gt;
            &lt;name&gt;Single market&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;12&quot;&gt;
            &lt;name&gt;Trade&lt;/name&gt;
          &lt;/interest&gt;
          &lt;interest index=&quot;13&quot;&gt;
            &lt;name&gt;Transport&lt;/name&gt;
          &lt;/interest&gt;
        &lt;/interests&gt;
      &lt;/interestRepresentative&gt;
    &lt;/resultList&gt;
  &lt;/ListOfIRPublicDetail&gt;
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>    try:
          register_tree = ET.parse(REGISTER_XML)
          register_root = register_tree.getroot()
      except:
          sys.exit(&quot;&quot;&quot;⚠️ Impossible d'ouvrir le registre. \n\n&quot;&quot;&quot;)
  
      # Get all companies name
      for xml in register_root.findall(&quot;.//{*}resultList/&quot;):
          print(xml.find(&quot;{*}name/{*}originalName&quot;).text)
      
      print('\n=============\n')
  
      # Get categories of interest
      for xml in register_root.findall(&quot;.//{*}resultList/&quot;):
          for child in xml.findall(&quot;{*}interests/{*}interest/{*}name&quot;):
              print(child.text)
          print('\n')
      
      print('\n=============\n')
  
      # Filter categories
      for xml in register_root.findall(&quot;.//{*}resultList/{*}interests/{*}interest/[{*}name='Digital economy and society']&quot;):
          print(xml)
  </code></pre>
  <pre class="lang-sh prettyprint-override"><code>F. Hoffmann-La Roche Ltd
  Nickel Institute
  
  =============
  
  Budget
  Business and Industry
  Climate Action
  Competition
  Consumers
  Digital economy and society
  Economy, finance and the euro
  Environment
  External Relations
  Institutional affairs
  International co-operation and development
  Justice and Fundamental Rights
  Public Health
  Research and innovation
  Single market
  Trade
  
  
  Business and Industry
  Climate Action
  Consumers
  Economy, finance and the euro
  Employment and Social Affairs
  Energy
  Environment
  Food Safety
  Public Health
  Research and innovation
  Single market
  Trade
  Transport
  
  
  
  =============
  
  </code></pre>