18 lines
402 B
Python
18 lines
402 B
Python
# Installer d'abord lxml avec pip install lxml
|
|
from lxml import etree
|
|
|
|
# Read content from XML file
|
|
with open("demo.xml", "rb") as file:
|
|
text = file.read()
|
|
|
|
# Read structure into Element object
|
|
structure = etree.fromstring(text)
|
|
print(type(structure))
|
|
|
|
print(structure.text)
|
|
print(structure.attrib)
|
|
for child in structure:
|
|
print(child, type(child), child.attrib)
|
|
|
|
print(structure.find("user"))
|