file handling port_xml_dom(function in three partsstarting with the def line and the nested get_text(function def import_xml_dom(selffilename)def get_text(node_list)text [for node in node_listif node nodetype =node text_nodetext append(node datareturn "join(textstrip(the get_text(function iterates over list of nodes ( node' child nodes)and for each one that is text nodeit extracts the node' text and appends it to list of texts at the end the function returns all the text it has gathered as single stringwith whitespace stripped from both ends trydom xml dom minidom parse(filenameexcept (environmenterrorxml parsers expat expaterroras errprint("{ }import error{ }formatos path basename(sys argv[ ])err)return false parsing an xml file into dom is easy since the module does all the hard work for usbut we must be ready to handle expat errors since just like an element treethe expat xml parser is the default parser used by the dom classes under the hood self clear(for element in dom getelementsbytagname("incident")trydata {for attribute in ("report_id""date""aircraft_id""aircraft_type""pilot_percent_hours_on_type""pilot_total_hours""midair")data[attributeelement getattribute(attributedata["date"datetime datetime strptimedata["date"]"% -% -% "date(data["pilot_percent_hours_on_type"float(data["pilot_percent_hours_on_type"])data["pilot_total_hours"intdata["pilot_total_hours"]data["midair"bool(int(data["midair"])airport element getelementsbytagname("airport")[