[XML-SIG] How to use PyExpat ExternalParsedEntityDeclHandler?

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Tue, 31 Jul 2001 08:09:02 +0200


> PYE = PyExpat.Reader
> class ReaderforC14NExamples(PYE):
>     def initParser(self):
>         PYE.initParser(self)
>         self.parser.UnparsedEntityDeclHandler = self.unparsedEntityDecl
>         self.parser.NotationDeclHandler = self.notationDecl
>         self.parser.ExternalParsedEntityDeclHandler = self.entityDecl
>  
>     def entityDecl(self, *args):
>         if args != ('ent2', None, 'world.txt', None): return
>         print 'match'
> >>>     self.parser.CharacterDataHandler('world')
>         return 0
> 
> Doesn't do what I thought it would.

Well, what did you think it would do? Replace every occurrence of the
external entity with "world"? Then you should handle the references to
the external entities, not the declaration. I.e. you should set the
ExternalEntityRefHandler. See expatreader for an example of how to do
this.

Regards,
Martin