Bonjour,
je galère avec un xpath et xml.etree.ElementTree, voici un exemple de xml:
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <AAAA xmlns="http://wb/ECO/SSS"> <BBB xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <CCC> <DDD> <EEE>123456</EEE> <FFF>23/06/2021 16:00:00</FFF> <GGG>23/06/2021 17:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> <DDD> <EEE>123457</EEE> <FFF>05/07/2021 10:00:00</FFF> <GGG>05/07/2021 11:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> <DDD> <EEE>123458</EEE> <FFF>19/07/2021 15:00:00</FFF> <GGG>19/07/2021 16:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> </CCC> <CodeRetour>1</CodeRetour> <Message>blablabla</Message> </BBB> </AAAA> </s:Body> </s:Envelope>
et j'essaye d'avoir tous les EEE sous forme de liste.. help !!!
merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 import xml.etree.ElementTree as ET toto = '''<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <AAAA xmlns="http://webres/ECO/Speed"> <BBB xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <CCC> <DDD> <EEE>123456</EEE> <FFF>23/06/2021 16:00:00</FFF> <GGG>23/06/2021 17:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> <DDD> <EEE>123457</EEE> <FFF>05/07/2021 10:00:00</FFF> <GGG>05/07/2021 11:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> <DDD> <EEE>123458</EEE> <FFF>19/07/2021 15:00:00</FFF> <GGG>19/07/2021 16:00:00</GGG> <HHH i:nil="true"/> <III i:nil="true"/> </DDD> </CCC> <CodeRetour>1</CodeRetour> <Message>blablabla</Message> </BBB> </AAAA> </s:Body> </s:Envelope>''' print(toto) root = ET.fromstring(toto) print(root.findall("./s/s/AAAA/BBB/CCC/DDD/EEE"))
Partager