O/S: Windows XP
ElementTree resides in the c:\python24\lib \site-packages\elemen ttree\
folder
When a string that does not contain well-formed XML is passed as an
argument to the XML() method in ElementTree.py, an ExpatError exception
is raised. I can trap the exception with a try/except where the except
does not specify a specific exception, but I cannot figure out how to
construct the except clause in a try/except statement to catch the
ExpatError exception. Interactive window illustrates
import elementtree.Ele mentTree as ElemTree
badxml = '<response>abc </responsez>'
root = ElemTree.XML(ba dxml) Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
File "C:\Python24\Li b\site-packages\elemen ttree\ElementTr ee.py", line
960, in XML
parser.feed(tex t)
File "C:\Python24\Li b\site-packages\elemen ttree\ElementTr ee.py", line
1242, in feed
self._parser.Pa rse(data, 0)
ExpatError: mismatched tag: line 1, column 15 try: .... root = ElemTree.XML(ba dxml)
.... except:
.... print 'some exception raised'
....
some exception raised try:
.... root = ElemTree.XML(ba dxml)
.... except ExpatError:
.... print 'ExpatError exception raised'
....
Traceback (most recent call last):
File "<interacti ve input>", line 3, in ?
NameError: name 'ExpatError' is not defined
I'm guessing that I need to define/describe the ExpatError exception
class and then refer to that defined exception class after the keyword
'except' and before the ':', but I cannot figure out how to do that.