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:
\DC\Events\Confirmation[contains(TransactionId,"GTEREVIEW")]
When I try to use lxml to do so, my code is:
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*']")
But this doesn't seem to work. Can anyone help? Example of XML file:
<Events>
<Confirmation>
<TransactionId>GTEREVIEW2012</TransactionId>
</Confirmation>
<Confirmation>
<TransactionId>GTEDEF2012</TransactionId>
</Confirmation>
</Events>
So I want all "Confirmation" nodes that contain a transaction Id which includes the string "GTEREVIEW". Thanks