For one of my recent 3D animation projects, I wanted to take data that was exported out to an XML file and parse the nodes' values to lists. I found a really simple way to search for and store all values from an XML file using The ElementTree XML API. These few lines of code open and parse the given XML file, then iterate over all the children under the root node and search for the children named Time and Name and then append them to separate lists. These lists can then be iterated over to utilize the values that were taken from the XML.

import xml.etree.ElementTree as etree

times = []
keys = []

def main():
    tree = etree.parse('/Users/Documents/Programming/Python/xml/samskeyti.xml')
    root = tree.getroot()

    for child in root:
        times.append(child.find('Time').text)
        keys.append(child.find('Name').text)

if __name__ == "__main__": main()

The XML file looks something like this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<FLVCoreCuePoints Version="1">
 
  <CuePoint>
    <Time>90923</Time>
    <Type>event</Type>
    <Name>d5</Name>
  </CuePoint>
 
  <CuePoint>
    <Time>91347</Time>
    <Type>event</Type>
    <Name>eb5</Name>
  </CuePoint>
 
  <CuePoint>
    <Time>91701</Time>
    <Type>event</Type>
    <Name>d5</Name>
  </CuePoint>
 
</FLVCoreCuePoints>