I am parsing an XML payload using ElementTree. I cannot share the exact code or file as it shares sensitive information. I am able to successfully extract the information I need by iterating through an element (as seen in the ElementTree documentation) and appending the output to lists. For example:
list_col_name = []
list_col_value = []
for col in root.iter('my_table'):
# get col name
col_name = col.find('col_name').text
list_col_name.append(col_name
# get col value
col_value = col.find('col_value').text
list_col_value.append(col_value)
I can now put these into a dictionary and proceed with the remainder of what needs to be done:
dict_ = dict(zip(list_col_name, list_col_value))
However, I need this to happen as quickly as possible and am wondering if there is a way in which I can extract list_col_name
at once (i.e., using findall()
or something like that). Just curious as to way to increase the speed of xml parsing if possible. All answers/recommendations are appreciated. Thank you in advance.