Problem with using xml with jython

sean.mcgrath at propylon.com sean.mcgrath at propylon.com
Thu Jul 19 11:02:02 EDT 2001


I had the same problem. makeparser() is defaulting to expat which is a
C module. I worked around it by specifying xmlproc as the parser:

	parser = sax.make_parser("xml.sax.drivers2.drv_xmlproc")

This will then work on both Python and Jython. It takes responsibility
for choosing a parser ouf of the XML utilities and into your code.
This may or may not be acceptable depending on your application.

Sean


On 18 Jul 2001 13:34:22 -0700, gmulchan at hotmail.com (Gautam) wrote:

>Hi,
>   I am trying to run a simple program shown below with jython. It
>runs with python successfully but throws the following exception when
>run with jython. Can someone point out the problem.
>   I am using python 2.0. on win2k. I downloaded the xml package very
>recently.
>
>Thx
>
>program starts here 
>--------------------------------
>import sys
>
>from xml.sax import saxutils
>from xml.sax import make_parser
>from xml.sax.handler import feature_namespaces
>
>#print sys.modules
>    
>file='test.xml'
>
>class FindIssue(saxutils.DefaultHandler):
>    def __init__(self, title, number):
>        self.search_title, self.search_number = title, number
>
>    def startElement(self,name,attrs):
>        if name != 'comic' : return
>
>        title = attrs.get('title', None)
>        number = attrs.get('number',None)
>        if title == self.search_title and number ==
>self.search_number:
>            print title, '#'+str(number), 'found'
>        
>if __name__ == '__main__':
>    parser = make_parser()
> #   parser.setFeature(feature_namespaces,0)
>
>    dh = FindIssue('Sandman', '62')
>    parser.setContentHandler(dh)
>    parser.parse(file)
>
>----------------------------------------------------------
>
>The exception in jython is :
>
>C:\pythoncode\xmltest>C:\jython-2.0\jython trial.py
>Traceback (innermost last):
>  File "trial.py", line 24, in ?
>  File "C:\jython-2.0\_xmlplus\sax\sax2exts.py", line 34, in
>make_parser
>  File "C:\jython-2.0\_xmlplus\sax\saxexts.py", line 75, in
>make_parser
>KeyError: xml.sax.drivers2.drv_pyexpat




More information about the Python-list mailing list