Using XPath in Python with LXML
<p>I have a python script used to parse XMLs and export into a csv file certain elements of interest. I have tried to now change the script to allow the filtering of an XML file under a criteria, the equivalent XPath query would be:</p>

<pre><code>\DC\Events\Confirmation[contains(TransactionId,"GTEREVIEW")]
</code></pre>

<p>When I try to use lxml to do so, my code is:</p>

<pre><code>xml_file = lxml.etree.parse(xml_file_path)
namespace = "{" + xml_file.getroot().nsmap[None] + "}"
node_list = xml_file.findall(namespace + "Events/" + namespace + "Confirmation[TransactionId='*GTEREVIEW*']")
</code></pre>

<p>But this doesn't seem to work. Can anyone help?
Example of XML file:</p>

<pre><code>&lt;Events&gt;
  &lt;Confirmation&gt;
    &lt;TransactionId&gt;GTEREVIEW2012&lt;/TransactionId&gt;
  &lt;/Confirmation&gt;    
  &lt;Confirmation&gt;
    &lt;TransactionId&gt;GTEDEF2012&lt;/TransactionId&gt;
  &lt;/Confirmation&gt;    
&lt;/Events&gt; 
</code></pre>

<p>So I want all "Confirmation" nodes that contain a transaction Id which includes the string "GTEREVIEW".
Thanks</p>