ElementTree should parse string and file in the same way

Fredrik Lundh fredrik at pythonware.com
Thu Jan 3 07:49:03 EST 2008


Stefan Behnel wrote:

>> My take on the API decision in question was always that a file is
>> inherently an XML *document*, while a string is inherently an XML
>> *fragment*.
> 
> Not inherently, no. I know some people who do web processing with an XML
> document coming in as a string (from an HTTP request)  /.../

in which case you probably want to stream the raw XML through the parser 
*as it arrives*, to reduce latency (to do that, either parse from a 
file-like object, or feed data directly to a parser instance, via the 
consumer protocol).

also, putting large documents in a *single* Python string can be quite 
inefficient.  it's often more efficient to use lists of string fragments.

</F>




More information about the Python-list mailing list