lundi 11 janvier 2016

How to solve the StopIteration issue while the XML tag does not have a value using Python script

I am using ixml to parse the XML doxument.

from lxml import etree
root=etree.XML(full xml tag file content)
 if (next(root.iterfind(".//one_inner_tag")).text is None):
      Print "NONE VALUE"
 else:
      Print root.iterfind(".//one_inner_tag")).text

While executing this code, I have faced an error like

if (next(root.iterfind(".//one_inner_tag")).text is None):
StopIteration

Because of the file content does not have that specific tag. If the Tag does not have a value means I need to print the NONE VALUE. But it prints the error.

Aucun commentaire:

Enregistrer un commentaire