I am parsing an XML file and trying to find some XML tags. I'm looking for the tag personalDataRelated
and when running it depending on XML file, I either get one of the two values below :
<Element 'personalDataRelated' at 0x0000020417C86AC0>
None
What I do next is depending on the value I get previously my variable data
gets a special value attributed, but it doesn't work, and even if I get None
, it doesn't set data
as Non
import xml.etree.ElementTree as et
xmlfileName = 'new.xml'
xmlparse = et.parse(xmlfileName)
root = xmlparse.getroot()
print(root.find('personalDataRelated'))
if root.find('personalDataRelated') != 'None':
data = "Oui"
else:
data = "Non"
What am I doing wrong ?
CodePudding user response:
You're testing against the 'None'
string when you should be testing against the None
keyword.