Initial commit
This commit is contained in:
17
source/08-text-files/xml/xmlread.py
Normal file
17
source/08-text-files/xml/xmlread.py
Normal file
@ -0,0 +1,17 @@
|
||||
# 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"))
|
Reference in New Issue
Block a user