Eli Bendersky added the comment: Raymond, you are right that the APIs presented by Element and ElementTree are somewhat different. As Stefan mentioned, they were really meant to represent different things, but with time some "convenience" features crept in and made the difference somewhat more moot.
Note that some methods/functions in ET give you the root element directly, rather than the tree. For example the XML function, or fromstring function. Also, the tree implements the iter() method, which is morally equivalent to Element.iter() on the root node. However, the tree (unlike Element) is not iterable. Element implements __getitem__, the tree does not. Currently, the first code snippet in the official documentation shows: import xml.etree.ElementTree as ET tree = ET.parse('country_data.xml') root = tree.getroot() Which makes the distinction between the tree and its root. Whether this is a great API (making tree and root distinct), I can't say, but we can't change it now. Do you have concrete suggestions? Make the tree iterable? Add all element methods to the tree, implicitly forwarding to the root? Improve documentation? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21028> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com