-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtp32.py
More file actions
33 lines (24 loc) · 915 Bytes
/
tp32.py
File metadata and controls
33 lines (24 loc) · 915 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
32
import xml.etree.ElementTree as ET
import lxml.etree as ET
# Lecture du fichier XML
tree = ET.parse("tp32.xml")
root = tree.getroot()
# Récupération des informations sur les articles du stock
articles = root.findall(".//occasion") + root.findall(".//nouveau")
# Affichage des informations sur chaque article
for article in articles:
print("Article:")
libelle = article.find("libelle").text
print(" Libellé:", libelle)
category = article.find("category")
if category is not None:
print(" Catégorie:", category.text)
prix = article.find("prix")
if prix is not None:
prix_value = prix.text
devise = prix.attrib.get("devise", "EUR")
print(f" Prix: {prix_value} {devise}")
etat = article.find("etat")
if etat is not None:
print(" État:", etat.text)
print() # Ligne vide pour séparer les articles