Files
training.python.beginner/training/demos/08-text-files/lxml-demo/source/xml_read_demo.py
2025-07-04 19:26:39 +02:00

13 lines
417 B
Python

"""XML demo to parse a simple ctalog file."""
from lxml import etree
tree = etree.parse(r"files/catalog.xml") # Get the whole document as the root element
# Récupérer les éléments de la racine CATALOG qui ont le nom CD
items = tree.xpath("//CATALOG/CD")
for cd in items:
for attribute in cd:
print(attribute.tag, attribute.attrib) # afficher le nom et les attributs
print(attribute.text)