I have to parse XML that has tag names that may be in any case (mixed, upper, lower, etc) and I don\'t know what the case will be beforehand. How can I make findall be total
Regex to the rescue. Note this is probably horrific in terms of performance but is great at extracted 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(' ')
print getInsensitiveAttrbiute(element, "sRc")