[Expat-discuss] Setting a CDATA handler in Expat
Frank Moore
francis.moore at rawflow.com
Fri Apr 7 14:40:28 CEST 2006
Hi,
Can anyone tell me how to set a CDATA event handler in Python using Expat.
I'm currently using the Expat XML Parser (version 1.95.5).
And this is the Python code:
outFile = file(localPlayerHtml, 'w')
inFile = file(tempPlayerHtml, 'r')
htmlparser = saxexts.make_parser()
htmlhandler = PlayerHtmlHandler(outFile, stream)
htmlparser.setDocumentHandler(htmlhandler)
htmlparser.StartCdataSectionHandler =
PlayerHtmlHandler.startCDATA <-- here
htmlparser.EndCdataSectionHandler =
PlayerHtmlHandler.endCDATA <-- and here
htmlparser.parseFile(inFile)
The class PlayerHtmlHandler(saxlib.HandlerBase) in file
PlayerHtmlHandler.py contains the following two functions:
def startCDATA(self):
print "Starting CDATA..."
def endCDATA(self):
print "Finishing CDATA..."
And I'm including the contents of PlayerHtmlHandler using the import
statement:
from PlayerHtmlHandler import *
For some reason when I run the code, the two CDATA handlers are not called.
Can anyone see what I'm doing wrong?
Many thanks,
Frank.
More information about the Expat-discuss
mailing list