Reading an XML file with 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.
Understanding Reading an XML file with ElementTree in VCE Software Development U3O1
What it does: find() returns the first element with that tag, and .text gives the string between its opening and closing tags. ET.parse() reads the XML file and builds the tree. ET has no read() function for this. Everything read from an XML file is a string. Use int() or float() before doing any arithmetic. The module path is xml.etree.ElementTree. The 'as ET' part gives it the short name ET. findall() collects all matching child elements, so it is used with a for loop to work through repeated records.
Common mistakes: getroot is a method, so it needs brackets to be called. Without them root holds the method itself instead of the root element. It should be root = tree.getroot(). find() returns only the first matching element, not a list of all matches. To loop over every <pet> element use root.findall('pet').
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 114–124) and word search (Modules 114–141).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
xml.etree.ElementTreeFill in the Blanks
Spot the Error
Student with a class code? Join your class →