ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

Stefan Behnel stefan_ml at behnel.de
Fri Jun 26 01:11:33 EDT 2009


Carl Banks wrote:
>> Why isn't et.parse the only way to do this? Why have XML or fromstring  
>> at all?
> 
> Because Fredrick Lundh wanted it that way.  Unlike most Python
> libraries ElementTree is under the control of one person, which means
> it was not designed or vetted by the community, which means it would
> tend to have some interface quirks.

Just for the record: Fredrik doesn't actually consider it a design "quirk".
He argues that it's designed for different use cases. While parse() parses
a file, which normally contains a complete document (represented in ET as
an ElementTree object), fromstring() and especially the 'literal wrapper'
XML() are made for parsing strings, which (most?) often only contain XML
fragments. With a fragment, you normally want to continue doing things like
inserting it into another tree, so you need the top-level element in almost
all cases.

Stefan



More information about the Python-list mailing list