Python XML parsing missing element: 'None' vs None

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>

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()

if root.find('personalDataRelated') != 'None':
    data = "Oui"
    data = "Non"

What am I doing wrong ?

>Solution :

You’re testing against the 'None' string when you should be testing against the None keyword.

Leave a Reply