Sanitize and modernize some of the _elementtree code (see issue #16089).