I need to start with saying I'm totally new to writing code. I have been trying to grab information from a xml-file, unsuccessfully I might add. A smal snippet from the xml file is as follows:
<?xml version="1.0"?>
<AlertRequestType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DateTime xmlns="http://EU/Common/20181/">2021-06-15T08:55:08.441</DateTime>
<Code xmlns=>A68</Code>
<UniqueAlertId xmlns="http://EU/20181/">US-8I2-NVH-7JH-0A1-
54M</UniqueAlertId>
<Message xmlns="http://EU/Common/20181/">B-Id mismatch.</Message>
<Source xmlns="http://EU/2556781/">National S I</Source>
<SupportingData xmlns="http://EMVS.EU/Common/20181/">
<Item key="errorcode" value="A68" />
<Item key="errormessage" value="B-Id mismatch." />
<Item key="date" value="2021-06-15" />
<Item key="time" value="21:35:03" />
<Item key="uniquealertid" value="US-8I2-NVH-7JH-0A1-54M" />
<Item key="productcode" value="988356696047773" />
<Item key="serialnumber" value="PFL72KBN85S22" />
<Item key="b-id" value="QD88223402+G+1332" />
</SupportingData>
</AlertRequestType>
Now, my question as a person with very poor understanding for ElementTree and coding in general: How can I grab a value from a specific "<Item key="? For example from the item key errorcode with the value of A68. The real kicker is that all the values will change as i will use these values for work with different files every day (the item key attributes such as date or errorcode will never change, just the values of them), so I cant just code to search for one specific value, it needs to grab the value from that exact xpath everytime.
Down below is the code I've tried to modify to fit my needs, but alas to no success.
import xml.etree.ElementTree as ET
import os
xmlfile = 'xmltest.xml'
fullfile = os.path.abspath(os.path.join('filer', xmlfile))
tree = ET.parse(fullfile)
root = tree.getroot()
ET.dump(tree)
for elm in root.findall("./SupportingData/Item key/errorcode[@value=]"):
print(elm.attrib)
Again, this code is from someone completely new to coding. If someone could help me with this I'd be eternally gratefull!