xml,sax,EntityResolver

Achim Domma achim.domma at syynx.de
Tue Mar 20 05:36:09 EST 2001


ups ... sorry for the pgp-post !


Hi,

I try to process a sgml-file via sax. The file contains 'undefined
entities' which I don't care about, so would like to ignore them. I
have tried to derive my Handler from EntityResolver and have
resolveEntity overloaded.

Here is some code :

class
MyHandler(handler.ContentHandler,handler.ErrorHandler,handler.EntityRe
solver):
 def __init__(self):
  handler.ContentHandler.__init__(self)

 def startDocument(self):
  print "start"

 def startElement(self,name,attrs):
  print name

 def error(self, exception):
  print exception

 def fatalError(self, exception):
  print exception

 def warning(self, exception):
  print exception

 def resolveEntity(self, publicId, systemId):
  print publicID
  print systemID

parser = make_parser()
h = MyHandler()
parser.setContentHandler(h)
parser.setErrorHandler(h)
parser.setEntityResolver(h)
parser.parse("main.sgm")

If the parser reaches α in main.sgm fatalError is called twice,
but it seams that resolveEntity is never called - why ? What's the
simplest way to ignore such entities ?

greetings
Achim








More information about the Python-list mailing list