title: Python xml elementree how to check if element if present and process code?
body: <pre><code>&lt;rules&gt;
      &lt;entry name="rule name 1"&gt;
        &lt;to&gt;
          &lt;member&gt;untrust&lt;/member&gt;
        &lt;/to&gt;
        &lt;from&gt;
          &lt;member&gt;trust&lt;/member&gt;
        &lt;/from&gt;
        &lt;source&gt;
          &lt;member&gt;object1&lt;/member&gt;
        &lt;/source&gt;
        &lt;destination&gt;
          &lt;member&gt;any&lt;/member&gt;
        &lt;/destination&gt;
        &lt;service&gt;any&lt;/service&gt;
        &lt;description&gt;'NAT Rule 1'&lt;/description&gt;
        &lt;nat-type&gt;ipv4&lt;/nat-type&gt;
        &lt;source-translation&gt;
          &lt;static-ip&gt;
            &lt;bi-directional&gt;yes&lt;/bi-directional&gt;
            &lt;translated-address&gt;object1-pub&lt;/translated-address&gt;
          &lt;/static-ip&gt;
        &lt;/source-translation&gt;
      &lt;/entry&gt;
      &lt;entry name="rule name 2"&gt;
        &lt;to&gt;
          &lt;member&gt;untrust&lt;/member&gt;
        &lt;/to&gt;
        &lt;from&gt;
          &lt;member&gt;trust&lt;/member&gt;
        &lt;/from&gt;
        &lt;source&gt;
          &lt;member&gt;any&lt;/member&gt;
        &lt;/source&gt;
        &lt;destination&gt;
          &lt;member&gt;object2-pub&lt;/member&gt;
        &lt;/destination&gt;
        &lt;destination-translation&gt;
          &lt;translated-address&gt;object2&lt;/translated-address&gt;
        &lt;/destination-translation&gt;
        &lt;service&gt;any&lt;/service&gt;
        &lt;description&gt;'NAT Rule 2'&lt;/description&gt;
        &lt;tag&gt;
          &lt;member&gt;DST NAT&lt;/member&gt;
        &lt;/tag&gt;
      &lt;/entry&gt;
  &lt;/rules&gt;    
  </code></pre>
  
  <p>Hi,</p>
  
  <p>I am trying to process above xml using xml elementree in python. I am looking for a way to check if the &lt;'source-traslation'> or &lt;'destination-translation'> is present. In short, if it if source-translation then set nat-type varialble to source nat and proceed further to get  and &lt;'translated-address'> values. If &lt;'destination-address'> is present then process logic to get values for . I am putting all this data in a dict with a format like this...</p>
  
  <pre><code>rules{
          rule_name: &lt;name&gt;
          options:{
                  src_zone:&lt;from&gt;
                  source:&lt;source&gt;
                  dst_zone:&lt;to&gt;
                  destination:&lt;destination&gt;
                  nat-type:&lt;appliaction&gt;
                  service:&lt;service&gt;
                  traslated-address:&lt;translated-address&gt;
                  destination-address:&lt;destination-address&gt;
          }       
  }
  </code></pre>
  
  <p>I have tried various combinations however it is not working for me.</p>