xml.sax problem: getting parse() to read a string

sturnfie at gmail.com sturnfie at gmail.com
Mon Jun 5 18:34:48 CEST 2006

Hey all,  I recently came across the xml.sax libraries and am trying to
use them.  I am currently making a string variable, and am attempting
to pass it into a parser instance as follows:

 def parseMessage(self, message):
         #create a XML parser
         parser = make_parser()

         #create an instance of our handler class
         #generic, prints out to screen on all events
         dh = docHandler()

         #tell parser to use our handler

         #start it going, will trigger on events as defined in the
docHandler class

"message" is the following text:
<?xml version="1.0" ?>
    - <COMMAND>

This is dying with the following errors.

File "...../python/lib/python2.4/urllib.py", line 77, in urlopen
    return opener.open(url)
  File "...../python/lib/python2.4/urllib.py", line 180, in open
    return getattr(self, name)(url)
  File "...../python/lib/python2.4/urllib.py", line 409, in open_file
    return self.open_local_file(url)
  File "...../python/lib/python2.4/urllib.py", line 419, in
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: '?xml version="1.0" ?>\n-
<ENVELOPE>\n  - <MESSAGE>\n      <timestamp>timestamp</timestamp>\n
- <COMMAND>\n         <SCOPE>asdasd</SCOPE>\n
<ACTION>asdasds</ACTION>\n      </COMMAND>\n    </MESSAGE>\n

So in recap, it looks like it is trying to take my string argument as a
file handler.  How can I get around this?  I would prefer not to make a
bigger footprint on the system by creating a file......

Thanks in advance!

More information about the Python-list mailing list