title: python lxml get parent element when you know child text with xpath
body: <p>I have the following xml file: <em>test.xml</em></p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;SubmitTransaction xmlns="http://www.someaddress.com/someendpoint"&gt;
        &lt;objTransaction&gt;
          &lt;DataFields&gt;
            &lt;TxnField&gt;
              &lt;FieldName&gt;Pickup.Address.CountryCode&lt;/FieldName&gt;
              &lt;FieldValue&gt;DE&lt;/FieldValue&gt;
              &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
            &lt;/TxnField&gt;
            &lt;TxnField&gt;
              &lt;FieldName&gt;Pickup.Address.PostalCode&lt;/FieldName&gt;
              &lt;FieldValue&gt;10827&lt;/FieldValue&gt;
              &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
            &lt;/TxnField&gt;
            &lt;TxnField&gt;
              &lt;FieldName&gt;Pickup.DateTime&lt;/FieldName&gt;
              &lt;FieldValue&gt;2016-05-28T03:26:05&lt;/FieldValue&gt;
              &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
            &lt;/TxnField&gt;
            &lt;TxnField&gt;
              &lt;FieldName&gt;Pickup.LocationTypeCode&lt;/FieldName&gt;
              &lt;FieldValue&gt;O&lt;/FieldValue&gt;
              &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
            &lt;/TxnField&gt;
            &lt;TxnField&gt;
              &lt;FieldName&gt;Pickup.Address.City&lt;/FieldName&gt;
              &lt;FieldValue&gt;Berlin&lt;/FieldValue&gt;
              &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
            &lt;/TxnField&gt;
          &lt;/DataFields&gt;
        &lt;/objTransaction&gt;
      &lt;/SubmitTransaction&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>What I want to do is to get an element with tag <code>TxnField</code> that has a child <code>FieldName</code> with text <code>Pickup.DateTime</code>. It is important to get the parent element, so I need to get this:</p>
  
  <pre><code>&lt;TxnField&gt;
    &lt;FieldName&gt;Pickup.DateTime&lt;/FieldName&gt;
    &lt;FieldValue&gt;2016-05-28T03:26:05&lt;/FieldValue&gt;
    &lt;FieldIndex&gt;0&lt;/FieldIndex&gt;
  &lt;/TxnField&gt;
  </code></pre>
  
  <p>What I have so far is the following:</p>
  
  <pre><code>from lxml import etree
  xml_parser = etree.XMLParser(remove_blank_text=True)
  xml_tree = etree.parse('test.xml', xml_parser)
  
  p_time = xml_tree.xpath("//*[local-name()='TxnField']/*[text()='Pickup.DateTime']")
  print(p_time[0].tag) # {http://http://www.someaddress.com/someendpoint}FieldName
  </code></pre>
  
  <p>But this gives me the actual element with text <code>Pickup.DateTime</code> and I am interested in getting its parent as shown above.</p>
  
  <p><strong>As a side note</strong>: it took me almost an hour even to get this far because I find the lxml documentation to be very cumbersome. If anyone has a link with a good tutorial please post it at least as a comment. Thanks!</p>