title: How to parse XML depending on other parsing condition?
body: <p>I want to extract data from the XML, only if a particulair field is filled in the XML.</p>
  <p>The elements I want to extract are:</p>
  <ul>
  <li>The city: tag 110 code c (for example Berlin)</li>
  <li>The library code: tag 110 code g (for example D-Bbbf)</li>
  <li>The County code: tag 043 code c (for example XA-DE)</li>
  </ul>
  <p>This is a part from the XML:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;marc:record&gt;
    &lt;marc:controlfield tag="001"&gt;39612&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="003"&gt;DE-633&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="005"&gt;20161109000000.0&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="008"&gt;161109n|||||||a|||              a&lt;/marc:controlfield&gt;
    &lt;marc:datafield tag="043" ind1=" " ind2=" "&gt;
      &lt;marc:subfield code="c"&gt;XA-DE&lt;/marc:subfield&gt;
    &lt;/marc:datafield&gt;
    &lt;marc:datafield tag="110" ind1="2" ind2=" "&gt;
      &lt;marc:subfield code="a"&gt;Bibliothek für Bildungsgeschichtliche Forschung&lt;/marc:subfield&gt;
      &lt;marc:subfield code="c"&gt;Berlin&lt;/marc:subfield&gt;
    &lt;/marc:datafield&gt;
  &lt;/marc:record&gt;&lt;marc:record&gt;
    &lt;marc:controlfield tag="001"&gt;30006648&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="003"&gt;DE-633&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="005"&gt;20161109000000.0&lt;/marc:controlfield&gt;
    &lt;marc:controlfield tag="008"&gt;161109n|||||||a|||              a&lt;/marc:controlfield&gt;
    &lt;marc:datafield tag="043" ind1=" " ind2=" "&gt;
      &lt;marc:subfield code="c"&gt;XA-GB&lt;/marc:subfield&gt;
    &lt;/marc:datafield&gt;
    &lt;marc:datafield tag="110" ind1="2" ind2=" "&gt;
      &lt;marc:subfield code="a"&gt;The National Archives&lt;/marc:subfield&gt;
      &lt;marc:subfield code="c"&gt;London&lt;/marc:subfield&gt;
      &lt;marc:subfield code="g"&gt;GB-Lna&lt;/marc:subfield&gt;
    &lt;/marc:datafield&gt;
  &lt;/marc:record&gt;
   </code></pre>
  </div>
  </div>
  </p>
  <p><strong>Only if the library code tag is filled,</strong> I would like to extract the city and country code too.</p>
  <p>This is what I aready coded:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>data = []
  
  # Read the XML file
  with open('oefen.xml', 'r', encoding="utf8") as f_in:
      soup = BeautifulSoup(f_in.read(), 'html.parser') 
      
  for record in soup.find_all(tag="110"):
      data.append({
          'City' : e.get_text(strip=True) if (e := record.select_one('[code="c"]')) else None, # select city
          'Code' : e.get_text(strip=True) if (e := record.select_one('[code="g"]')) else None  # select code
      })
  
  for part in 'Code':
      if part != None:
          for record in soup.find_all(tag="043"):
              data.append({
                  'City Code' : e.get_text(strip=True) if (e := record.select_one('[code="c"]')) else None, # select city code
              })
  
  pd.DataFrame(data)</code></pre>
  </div>
  </div>
  </p>