[Tutor] xml parser problem.

pierre-yves.verdon pierre-yves.verdon@wanadoo.fr
Sat, 23 Feb 2002 14:34:59 +0100


hi,
i'm a new python user, and i'm trying to do an xml parser with the 
library xml.sax.
below is the link i've used for my code:
http://py-howto.sourceforge.net/xml-howto/node7.html
my python version is 2.2_1 (from the freebsd ports)
i just tried it and i get the error below.
Any help is welcome.

pierre-yves


Traceback (most recent call last):
  File "parse.py", line 4, in ?
    class FindIssue(saxutils.DefaultHandler):
AttributeError: 'module' object has no attribute 'DefaultHandler'


#
#here is the code
#

from xml.sax import saxutils, handler, make_parser
from xml.sax.handler import feature_namespaces

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.xml")