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?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to