Subclassing the Default ContentHandler : Handler : XML PYTHON examples


PYTHON examples » XML » Handler »

 

Subclassing the Default ContentHandler


 

from xml.sax import make_parser
from xml.sax import saxutils

class SimpleHandler(saxutils.DefaultHandler):
    def startElement(self,name,attrs):
        print 'Start: ',name,attrs
    def endElement(self,name):
        print 'End: ',name
    def characters(self,data):
        print 'Data: ', repr(data)

sh = SimpleHandler()
p = make_parser()
p.setContentHandler(sh)
file = "guac.xml"
p.parse(file)

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo XML
» Handler