XML parsing

Matt Gushee mgushee at havenrock.com
Mon Dec 13 10:32:34 EST 1999


philh at vision25.demon.co.uk (Phil Hunt) writes:

> 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?

Uh, first of all, could I ask why your input file starts with <?xml
version="1.1"?> -- since there isn't any such thing yet ... AFAIK
there isn't even a working draft for XML 1.1. *Please* don't tell me
somebody's going off and trying to create their own 'improved' version
of XML -- that's exactly how HTML got ruined.

If it were me, I'd want to have a conversation with the producer(s) of 
the documents about what is and is not XML. Or if their authoring
tools are at fault, find whoever programmed those tools and give them
an earfull.

But if you must accommodate this garbage, you might try writing your
own XMLParser class:

import xmllib

class XMLParser(xmllib.XMLParser):

    ## and define only the following method -- which you can cut and
    ## paste from xmllib.py, editing only the line that says
    ##     if version[1:-1] != '1.0':

    def goahead(self, end):

Hope this helps a bit. Oh, and if you happen to be part of a
super-secret group within the W3C that is, unbeknownst to the unwashed 
masses, actually working on XML 1.1, I apologize for the above rant.

Matt Gushee
Portland, Maine, USA





More information about the Python-list mailing list