Bonjour,
Certainement déjà posé comme question mais comment je fait pour utiliser XPath avec une variable, soit un truc comme ça :
Voic le xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 from lxml import etree Dataid = 856 root = etree.parse("MonXML.xml").getroot() Info = root.xpath("//Information[@DataID = Dataid]/text()") print(Info)
<test>
<Information DataID="856">77</Information>
</test>
Mon code marche puisqu'avec [@DataID = 856], print(Info) me sort [77].
Cependant, avec [@DataID = Dataid], ça me sort [].
Je cherche donc à savoir comment je peut utiliser ma variable Dataid pour plus tard n'avoir qu'à donner le Dataid pour qu'il me donne l'information !
Merci de votre temps !![]()
Partager