etree get attribute as a value instead of a string
For a given Element, I want to check whether the xsi:nil attribute is set to true.
My current code is
xsinil = dataFact.get('{开发者_如何学编程http://www.w3.org/2001/XMLSchema-instance}nil', False)
But instead of being True xsinil is of type string...
What's the best solution? I don't think this is very elegant:
xsinil=dataFact.get('{http://www.w3.org/2001/XMLSchema-instance}nil', False)
if xsinil == 'true' or xsinil == '1' :
xsinil = True
This looks nicer:
xsinil = dataFact.get('...', False) in ('true', '1')
It assigns True to xsinil variable only if result of get function is one of True, 'true' or '1'.
The second arg of Element.get() is almost irrelevant -- just don't use True.
All that you need is:
xsinil = dataFact.get('......') in ('true', '1')
加载中,请稍侯......
精彩评论