XML parsing

Phil Hunt philh at vision25.demon.co.uk
Sun Dec 12 20:26:02 EST 1999


I am parsing some XML input using the xmllib module.

I am getting an error because my input file starts with
<?xml version="1.1" ...
but xmllib checks for this and raises an exception because it
isn't version 1.0.

Is there any way to get xmllib to attempt to do something
sensible when it gets input it doesn't like, rather than just
raising an exception and refusding to read the file?

Or do I have to write my own XML parser?

On a more general note, does anyone else think that exceptions are
usually more trouble than they are worth? (I've only ever come
across two places where they are useful. One is writing a recursive
descent parser where you get an error and you want it to back up through
several levels of the subroutine stack at once, and the other is
the rather ingenious way that Python uses it to obviate the need
for iterators in for loops. But the first is a bit superfluous,
since i never write parsers directly these days -- I always use
tools like yacc or SPARK, and the second is very specialised).

-- 
Phil Hunt - - - phil at comuno.com
"Software is like sex, it's better when it's free" -- Linus Torvalds




More information about the Python-list mailing list