-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtp31.py
More file actions
32 lines (27 loc) · 1022 Bytes
/
tp31.py
File metadata and controls
32 lines (27 loc) · 1022 Bytes
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
import xml.etree.ElementTree as ET
import lxml.etree as ET
# Lecture du fichier XML
tree = ET.parse("tp31.xml")
root = tree.getroot()
# Récupération des informations de la commande
orderid = root.attrib.get("orderid")
client = root.find("client").text
livraison = root.find("livraison")
adresse = livraison.find("adresse").text
ville = livraison.find("ville").text
pays = livraison.find("pays").text
items = root.findall("item")
# Affichage des informations de la commande
print("Commande ID:", orderid)
print("Client:", client)
print("Adresse de livraison:", adresse)
print("Ville de livraison:", ville)
print("Pays de livraison:", pays)
print("Items de la commande:")
for item in items:
category = item.attrib.get("category")
libelle = item.find("libelle").text
quantite = item.find("quantite").text
prix = item.find("prix").text
devise = item.find("prix").attrib.get("devise", "EUR")
print(f" - Catégorie: {category}, Libellé: {libelle}, Quantité: {quantite}, Prix: {prix} {devise}")