title: Get etree Element with attribute, or containing subelement with attribute
body: <p>I have an XML file to parse, and I need to find elements by id.</p>
  
  <p>In the example code, I need to find the name of the <code>driver</code>, but I don't know whether my id is for the <code>vehicle</code>, <code>engine</code>, or <code>block</code>. I would like a solution which would work with arbitrary xml inside of <code>vehicle</code> (but existence of <code>driver</code> is guaranteed).</p>
  
  <pre><code>&lt;road&gt;
      &lt;vehicle id="16"&gt;
          &lt;driver&gt;Bob Johnson&lt;/driver&gt;
          &lt;engine id="532"&gt;
              &lt;type&gt;V8&lt;/type&gt;
              &lt;block id="113"&gt;
                  &lt;material&gt;Aluminium&lt;/material&gt;
              &lt;/block&gt;
          &lt;/engine&gt;
      &lt;/vehicle&gt;
      &lt;vehicle id="452"&gt;
          &lt;driver&gt;Dave Edwards&lt;/driver&gt;
          &lt;engine id="212"&gt;
              &lt;type&gt;Inline 6&lt;/type&gt;
              &lt;block id="381"&gt;
                  &lt;material&gt;Cast Iron&lt;/material&gt;
              &lt;/block&gt;
          &lt;/engine&gt;
      &lt;/vehicle&gt;
  &lt;/road&gt;
  </code></pre>
  
  <p><strong>What have I tried</strong></p>
  
  <p>I was trying to get the elements by their id, and then, if they weren't <code>vehicle</code> tags, navigate up the tree to find it, but it seems python's <code>elem.find()</code> returns None if the result is outside <code>elem</code>.</p>
  
  <p>Looking at <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element%22the%20docs%22" rel="nofollow">the docs</a>, they have this example:</p>
  
  <pre><code># Nodes with name='Singapore' that have a 'year' child
  root.findall(".//year/..[@name='Singapore']")
  </code></pre>
  
  <p>But I don't see how to make that work for any descendant, as opposed to a decendant on a specific level.</p>