[Expat-discuss] expat and compressed xml

Michal Molhanec michal at molhanec.net
Wed Jan 13 02:22:12 CET 2010


On Tue, 12 Jan 2010 15:37:47 -0700 "gilbert F." <gilbertff at gmail.com>
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))



More information about the Expat-discuss mailing list