Python parsing XML file problem with SAX

Stefan Behnel stefan_ml at behnel.de
Mon Aug 9 13:31:20 EDT 2010


Aahz, 09.08.2010 18:52:
> In article<mailman.1250.1280314148.1673.python-list at python.org>,
> Stefan Behnel wrote:
>>
>> First of all: don't use SAX. Use ElementTree's iterparse() function. That
>> will shrink you code down to a simple loop in a few lines.
>
> Unless I'm missing something, that only helps if the final tree fits into
> memory.  What do you suggest other than SAX if your XML file may be
> hundreds of megabytes?

Well, what about using ElementTree's iterparse() function in that case? 
That's what it's good at, and its cElementTree version is extremely fast.

Stefan




More information about the Python-list mailing list