Re: expat and compressed xml

Michal Molhanec <[email protected]> Wed, 13 Jan 2010 02:22:12 +0100
Newsgroups gmane.text.xml.expat.general
Message-ID <20100113022212.00007f8a@unknown>
On Tue, 12 Jan 2010 15:37:47 -0700 "gilbert F." <[email protected]>
wrote:

> Hello,
> 
> Here is a quick question about parsing xml .gz file. Here is what I
> did. With the following script
> 
> req = urllib2.Request(query_url)
> xml_file = urllib2.urlopen(req).read()
> 
> I downloaded a compressed xml file.  The file has a suffix of ".gz".
> 
> Now I used
> 
> p = xml.parsers.expat.ParserCreate()

You can do:

from StringIO import StringIO
from gzip import GzipFile
p.ParseFile(GzipFile(fileobj=StringIO(xml_file))