Expat crashing Python (was: RE: [XML-SIG] Parsing DTDs)

Radestock, Guenter guenter.radestock@sap.com
Mon, 12 Feb 2001 18:26:29 +0100

> > like there is no intermediate representation of the DTD 
> that can (or should)
> > be used for other purposes than validating XML.  Is this 
> correct?  Have
> > I looked at the wrong piece of code (i.e. is there something in the
> > 4suite package I could use?
> You can access a DTD object that gets generated from the parsing. The
> following sample code comes from the xmltools utility set 
> that uses the
> DTD information to generate contextual menus for an XML 
> editor. There is
> extensive API documentation on Lars Marius Garshol's page
> (http://www.garshol.priv.no/download/software/xmlproc/)

Thanks a lot for the quick help.  It works perfectly well now.

There seems to be a problem in pyexpat.  It crashes, when I feed it
a file with an incorrect XML prefix, something like:

<?xml version="1.0" encoding="iso-8859-1" tralala="123"?>


<?xml encoding="iso-8859-1" ?>

I can reproduce this under Windows 2000, Python 2.0 (bombs out of python
a memory error):

from xml.parsers import expat
po = expat.ParserCreate('ISO-8859-1')
po.Parse("""<?xml encoding="iso-8859-1" ?><test></test>""", 1)

***thinking a little***

trying outside emacs, I see a stack trace before it bombs out.  so I
insert an exception handler:

from xml.parsers import expat
po = expat.ParserCreate('ISO-8859-1')
exc = None
    po.Parse("""<?xml encoding="iso-8859-1" ?><test></test>""", 1)
except exc, arg:
    global xxx
    xxx = (exc, arg)

and now I get:

Traceback (most recent call last):
  File "C:\perforce\workplace\ims\dev\python-api\python\xml\expattest.py",
9, in ?

SystemError: 'finally' pops bad exception

Seems to be a problem of some exception handler in the Expat module.