Model structured documents with elements, attributes, namespaces, schemas, parsing, and transformations.
Lessons
Read XML with ElementTree.
Parsing XML in Python is easiest to learn by reading the example, changing it, and observing the result.
import xml.etree.ElementTree as ET
tree = ET.parse('lessons.xml')
root = tree.getroot()
for lesson in root.findall('lesson'):
title = lesson.find('title').text
level = lesson.get('level')
print(f"{title} [{level}]")Practice the Parsing XML in Python example in a small scratch file, then explain what changed and why.