ExpatError attributes
Daniel Nogradi
nogradi at gmail.com
Fri Nov 4 09:14:29 EST 2005
According to the documentation the xml.parsers.expat module provides the
exception ExpatError and
this exception has 3 attributes, lineno, offset and code. I would like to
use lineno, but can't.
ExpatError itself works, for example if I do
import sys
from xml.dom import minidom
from xml.parsers.expat import ExpatError
try:
minidom.parse("my.xml")
except ExpatError:
print 'The file my.xml is not well-formed.'
and then if the file my.xml is not well-formed, the program says so. Now I
would like to tell the user
on which line the problem is in my.xml, and the attribute lineno is supposed
to do just this. But if I have
import sys
from xml.dom import minidom
from xml.parsers.expat import ExpatError
try:
minidom.parse("my.xml")
except ExpatError:
print 'The file my.xml is not well-formed.'
print 'And the problem is here: ', ExpatError.lineno
then I get an error message:
Traceback (most recent call last):
File "./test", line 11, in ?
print 'And the problem is here: ', ExpatError.lineno
AttributeError: class ExpatError has no attribute 'lineno'
So how can I access the line number on which an xml error occured?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051104/0691197f/attachment.html>
More information about the Python-list
mailing list