Any way to get current file position in xml.parsers.expat?

C. Laurence Gonsalves clgonsal at keeshah.penguinpowered.com
Fri Jul 13 03:18:36 EDT 2001


I'm writing a little utility that uses xml.parsers.expat (this is in
Python 2.1) to parse XML. I want to be able to generate semantic error
messages, in addition to the syntacic errors that expat handles.  For
example, if the value of an attribute is invalid for whatever reason,
I'd like to be able to say "Invalid attribute 'foo': line 86, column 5"
(or something along those lines)

Unfortunately, I can't find any way to get the current position in the
file when using ParseFile. I know that if expat throws an ExpatError,
that will contain the line and column number, but that doesn't help me
in this situation, as the file is 'well formed' XML as far as expat is
concerned.

So is there any way to ask the expat parser where it is in the file?
Even a byte offset from the beginning of the file would be better than
nothing.

-- 
  C. Laurence Gonsalves                "Any sufficiently advanced
  clgonsal at kami.com                     technology is indistinguishable
  http://cryogen.com/clgonsal/          from magic." -- Arthur C. Clarke



More information about the Python-list mailing list