Parse xml file

Mag Gam magawake at gmail.com
Sun Aug 30 10:27:10 EDT 2009


XML is a structured file. I never knew you can read it line by line
and process. iterparse()

More info on iterparse():
http://effbot.org/zone/element-iterparse.htm


On Thu, Aug 27, 2009 at 10:39 AM, Stefan Behnel<stefan_ml at behnel.de> wrote:
> loial wrote:
>> Is there a quick way to retrieve data from an xml file in python 2.4,
>> rather than read the whole file?
>
> ElementTree is available as an external package for Py2.4 (and it's in the
> stdlib xml.etree package since 2.5).
>
> It's pretty much the easiest way to get data out of XML files.
>
> If your statement "rather than read the whole file" was referring to the
> file size, note that the C implementation "cElementTree" of ElementTree is
> very memory efficient, so you might still get away with just reading the
> whole file into memory. There's also the iterparse() function which
> supports iterative parsing of an XML file and thus allows intermediate
> cleanup of used data.
>
> Stefan
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list