[英]Checking for None value while parsing a XML
I am parsing a XML file.我正在解析一个 XML 文件。 I need to check for series_id field.
我需要检查 series_id 字段。 But i am unable to find a condition where the value is not there.
但我无法找到价值不存在的条件。 Tried None, len(has_series) = 0 but it never gives me a value.
试过 None, len(has_series) = 0 但它从来没有给我一个值。 Even i tried to check for False and " ".
即使我试图检查 False 和“”。 But not able to validate the condition.
但无法验证条件。
My Snippet below下面是我的片段
has_series = program.xpath('props/*[@title="Series_ID"]')
if has_series is None:
print "None Value"
if len(has_series) ==0:
print "Zero value"
if has_series == False:
series_id = "N"
else:
series_id = has_series[0].text
print series_id
Part from the XML without has_series部分来自没有 has_series 的 XML
<para352 title="Series_ID"></para352>
I need to find a check for no value.我需要找一张没有价值的支票。 The output comes like this.
输出是这样的。
Processing: /tmp/rosh/dummy/30000000550321045_2019_10_22T19_49_13Z.xml
Processing: /tmp/rosh/dummy/30000000550324403_2019_10_22T19_49_13Z.xml
Processing: /tmp/rosh/dummy/30000000550324407_2019_10_22T19_49_13Z.xml
Processing: /tmp/rosh/dummy/E30000001555205318_2019_10_09T12_19_38Z.xml
XN016663
Processing: /tmp/rosh/dummy/E30000001555205320_2019_10_09T12_19_38Z.xml
XN016663
Processing: /tmp/rosh/dummy/E30000001555332469_2019_10_09T12_19_38Z.xml
XN016663
wherever the values are picked, script displays it properly.无论在何处选取值,脚本都会正确显示它。 But i need to validate against a non value condition.
但我需要针对非价值条件进行验证。
通过使用 series_id.isalnum(),我可以检查空值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.