Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1root = ET.parse('students.xml').getroot() | AReturns a list of every child element of root that is named student | |
| 2root.findall('student') | BParses the XML file into a tree and stores its top-level (root) element in a variable | |
| 3Use find() to reach one child element, then .text to read the value stored inside it | CMissing .text, so this prints the element object rather than the value inside it. Fix: student.find('name').text | |
| 4Use .get() on an element to read the value of one of its attributes | Did = student.get('id') | |
| 5print(student.find('name')) | Efind() returns only the first matching element, not a list to loop over. Fix: root.findall('student') | |
| 6for s in root.find('student'): | Fname = student.find('name').text |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
xml.etree.ElementTree — Python module that parses an XML file into a tree of elements. Use find() and findall() to reach elements and .text to read their values.import xml.etree.ElementTree as ET
tree = ET.parse("students.xml")tree = ET.parse("students.xml")
root = tree.getroot()for s in root.findall("student"):
print(s.find("name").text)for s in root.findall("student"):
name = s.find("name").textfor s in root.findall("student"):
print(s.get("id"))