What happens is that an element evaluates to False if it has no
children, and True if it does. The presence of text content, attributes
or a tail does not affect the boolean status; if no elements exist it'll
still be False.
find() has the behavior to return None if the value cannot be found. You
can change your tests to something like:
if xmldoc.find('child') is not None:
...
to check whether you have a child.
No comments:
Post a Comment