Regex to the rescue. Note that this is probably terrible in terms of performance, but great for retrieved XML attributes from elements.
def getInsensitiveAttrbiute(element, key) :
keyRegex = re.compile(key, re.IGNORECASE)
for key in element.attrib.keys() :
if keyRegex.match(key) :
return element.attrib[key]
raise KeyError
element = ET.fromstring('<FOO src="BAR" />')
print getInsensitiveAttrbiute(element, "sRc")
source
share