This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eli.bendersky
Recipients eli.bendersky, martin.panter, rhettinger, scoder
Date 2014-03-31.13:39:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396273168.48.0.406010400757.issue21028@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2014-03-31 13:39:28eli.benderskysetrecipients: + eli.bendersky, rhettinger, scoder, martin.panter
2014-03-31 13:39:28eli.benderskysetmessageid: <1396273168.48.0.406010400757.issue21028@psf.upfronthosting.co.za>
2014-03-31 13:39:28eli.benderskylinkissue21028 messages
2014-03-31 13:39:27eli.benderskycreate