xsd - Why do I get NoneType returned in my python script when an xml tag is missing -


here xml

<file>     <file_name>test1.fits</file_name> </file> <file>     <file_name>test2.fits</file_name>     <restricted>1</restricted> </file> 

here part of xsd

<xsd:complextype name="fileinfo">     <xsd:sequence>         <xsd:element name="file_name" type="xsd:string"             minoccurs="1" maxoccurs="1" />         <xsd:element name="restricted" type="xsd:integer"         minoccurs="0" maxoccurs="1" />     </xsd:sequence> </xsd:complextype> 

and here python code using lxml.etree

isrestricted=0 restricted = 0 filename = file.findtext('file_name') restricted = file.findtext('restricted') if restricted not none:     isrestricted = int(restricted) 

the above works looks kludgy. want assign isrestricted either value in xml if there or 0 if it's not there. right i've defined in xsd integer i'd rather boolean checking. tried using findtext default , got

traceback (most recent call last): file "file_tracking_populator.py", line 185, in print "isrestricted=" + str(isresricted) nameerror: name 'isresricted' not defined

i tried putting default in xsd , didn't work either.

when did

isrestricted = file.findtext('restricted') 

i got

traceback (most recent call last): file "file_tracking_populator.py", line 199, in isrestricted ); typeerror: %d format: number required, not nonetype

what doing wrong?


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -