I'm trying to parse this XML using Element Tree in the latest version of python. What I'd like to do is count the number of APPINFO elements and then get the data out of the latest instance of APPINFO (the last one in the tree). So far I am able to get the number of APPINFO elements using
count = len(root.findall("./APPINFO"))
But how do I reference only the last one in the tree and extract the values?
<APPLICANT>
<APPINFO>
<FIRSTNAME>Joe</FIRSTNAME>
<LASTNAME>Smith</LASTNAME>
<MIDDLENAME></MIDDLENAME>
<OTHERNAME></OTHERNAME>
</APPINFO>
<APPLICANT>
<APPINFO>
<FIRSTNAME>Peter</FIRSTNAME>
<LASTNAME>Smith</LASTNAME>
<MIDDLENAME></MIDDLENAME>
<OTHERNAME></OTHERNAME>
</APPINFO>
<APPINFO> #I need the data out of this one only
<FIRSTNAME>John</FIRSTNAME>
<LASTNAME>Smith</LASTNAME>
<MIDDLENAME></MIDDLENAME>
<OTHERNAME></OTHERNAME>
</APPINFO>
last=root.findall("./APPINFO")[-1]