From 33f7e5ba6139501137c909679da170ab972cfd91 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Tue, 4 Aug 2009 16:29:22 -0700 Subject: [PATCH] typo --- xml.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 to False if they contain no children (i.e. if len(element) is 0). The means that if element.find('...') is not testing whether the find() method found a matching element; it’s testing whether that matching element has any child elements! To test whether the find() method returned an element, use if 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 to False if they contain no children (i.e. if len(element) is 0). This means that if element.find('...') is not testing whether the find() method found a matching element; it’s testing whether that matching element has any child elements! To test whether the find() method returned an element, use if 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.