title: Parsing XML and printing attributes of one child that fits a given criteria
body: <p>I have an XML response. I need to extract the <code>uri</code> attribute where <code>local=1</code> in <code>Connection</code> under the <code>Device</code> labeled <code>product=Plex Media Server</code>, or to put it succinctly, I need <code>this.is.what.i.want</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;MediaContainer size="5"&gt;
    &lt;Device name="Cast" product="Plex Media Server" productVersion="1.14.1.5490-33830be0b" platform="Android" platformVersion="8.0.0" device="SHIELD Android TV" clientIdentifier="" createdAt="" lastSeenAt="" provides="" owned="1" accessToken="" publicAddress="" httpsRequired="1" synced="0" relay="1" dnsRebindingProtection="0" publicAddressMatches="1" presence="1"&gt;
      &lt;Connection protocol="https" address="12.34.56.78" port="xxx" uri="this.is.what.i.want" local="1"/&gt;
      &lt;Connection protocol="https" address="91.01.11.21" port="xxx" uri="https://111-111-111-111.863fffffffffffffflf.plex.direct:xxx" local="0"/&gt;
    &lt;/Device&gt;
    &lt;Device name="TV" product="Plex for Samsung" productVersion="2.012" platform="Samsung" platformVersion="5.1" device="Samsung TV" clientIdentifier="xxx" createdAt="" lastSeenAt="" provides="client,player,pubsub-player" owned="1" publicAddress="" publicAddressMatches="0" presence="0" accessToken=""&gt;
      &lt;Connection protocol="https" address="xx.xx.xx.xx" port="xx" uri="https://222-222-222-222.863ffffffffffffffff.plex.direct:xxx" local="1"/&gt;
      &lt;Connection protocol="https" address="xx.xx.xx.xx" port="xx" uri="https://333-444-555-666.863ffffffffffffffff.plex.direct:xxx" local="0"/&gt;
    &lt;/Device&gt;
  &lt;/MediaContainer&gt;
  </code></pre>
  
  <p>I'm a super newb. I can get the last uri to print</p>
  
  <pre><code>tree = ET.parse('test.xml')
  root = tree.getroot()
  
  for Connection in root.iterfind('Device/Connection'):
      uri = Connection.get('uri')
  
  print(uri)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>https://333-444-555-666.863ffffffffffffffff.plex.direct:xxx
  </code></pre>
  
  <p>However when I try to add some qualifiers my code falls apart:</p>
  
  <pre><code>tofind = set(['Device/@product'])
  
  for Device in root.findall('Device'):
      for product in tofind:
          node = Device.find('Plex Media Server')
          if node is not None:
              print ('Found uri')
          else:
              print ('Unable to find uri')
  
  print(Device.attrib)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Unable to find uri
  Unable to find uri
  {'name': 'TV', 'product': 'Plex for Samsung', 'productVersion': '2.012', 'platform': 'Samsung', 'platformVersion': '5.1', 'device': 'Samsung TV', 'clientIdentifier': 'xxx', 'createdAt': '', 'lastSeenAt': '', 'provides': 'client,player,pubsub-player', 'owned': '1', 'publicAddress': '', 'publicAddressMatches': '0', 'presence': '0', 'accessToken': ''}
  </code></pre>
  
  <p>For some reason the code always prints the last device attributes and not the first. </p>
  
  <p>Any help here is appreciated.</p>