Testing Equivalence of xml.etree.ElementTree
I'm interested in equivalence of two xml elements; and I've found that testing the tostring of the elements works; however, that seems hacky. Is there a better way to test equivalence of two etree Elements? Comparing Elements directly: import xml.etree.ElementTree as etree h1 = etree.Element('hat',{'color':'red'}) h2 = etree.Element('hat',{'color':'red'}) h1 == h2 # False Comparing Elements as strings: etree.tostring(h1) == etree.tostring(h2) # True This compare function works for me: def elements_equal(e1, e2): if e1.tag != e2.tag: return False if e1.text != e2.text: return False if e1.tail !