comparing (c)ElementTree and minidom (was: Parsing unicode (devanagari) text with xml.dom.minidom)

Stefan Behnel stefan_ml at behnel.de
Sun Mar 8 06:28:15 EDT 2009


Martin v. Löwis wrote:
>> The background was parsing the XML dump of an entire web site, which I
>> would expect to be larger than what minidom is designed to handle
>> gracefully. Switching to cElementTree before major code gets written is
>> almost certainly a good idea here.
> 
> I think minidom is designed to handle the very same documents taht
> cElementTree is designed to handle (namely, documents that fit into
> memory).

I do not doubt that a machine running a cElementTree application can handle
exactly the same documents as a machine with, say, ten times as much memory
that runs a minidom application. However, when deciding which library to
choose for a new application, it does matter what hardware you want to use
it on. And if you can handle multiple times larger documents on the same
hardware, that might be as much of reason to choose cElementTree as the
(likely) shorter and more readable code (which usually translates into
shorter development and debugging times) and the higher execution speed.
Honestly, I haven't seen a reason in a while why preferring minidom over
any of the ElementTree derivates would be a good idea when starting a new
application.

Stefan



More information about the Python-list mailing list