diff --git a/xml.html b/xml.html index 564adeb..9102211 100755 --- a/xml.html +++ b/xml.html @@ -386,7 +386,7 @@ mark{display:inline}
-☞There is a “gotcha” with the
find()method that will eventually bite you. In a boolean context, ElementTree element objects will evaluate toFalseif they contain no children (i.e. iflen(element)is0). The means thatif element.find('...')is not testing whether thefind()method found a matching element; it’s testing whether that matching element has any child elements! To test whether thefind()method returned an element, useif element.find('...') is not None. +☞There is a “gotcha” with the
find()method that will eventually bite you. In a boolean context, ElementTree element objects will evaluate toFalseif they contain no children (i.e. iflen(element)is0). This means thatif element.find('...')is not testing whether thefind()method found a matching element; it’s testing whether that matching element has any child elements! To test whether thefind()method returned an element, useif element.find('...') is not None.
There is a way to search for descendant elements, i.e. children, grandchildren, and any element at any nesting level.