xml.dom.minidom memory usage

Dan thermostat at gmail.com
Thu Feb 1 15:28:11 EST 2007


On Feb 1, 3:12 pm, Jonathan Curran <j... at icicled.net> wrote:
> Dan,
>         The DOM (Document Object Model) is such that it loads all the elements of the
> XML document into memory before you can do anything with it. With your file
> containing millions of child nodes this will eat up as much memory as you
> have. A solution to this is to use the SAX method of parsing XML documents
> and working on it. SAX is such that it only reads the XML doc. a node (or a
> few nodes) at a time.
>
> Unfortunately, the use of DOM or SAX completely depends on what kind of
> processing you need to be done on the XML document. If it is editing a record
> at a time (from what I've gathered from your code) it would be wise to use
> SAX. I highly suggest looking into this method of processing.
>
> - Jonathan Curran

Jonathan,

Thanks for the response. I'm comfortable using SAX for parsing, but
I'm unsure how it helps me with XML generation. To clarify in my
example code, with the DOM document, I can call doc.toxml() or
doc.toprettyxml(), and get the desired output (an xml file). AFAIK,
SAX has no analog, it just does parsing. Is there a way to do XML
generation with SAX that I'm unaware of?

-Dan




More information about the Python-list mailing list