Identifying End Element Tags Using SAX Parsing : SAX « XML « Python






Identifying End Element Tags Using SAX Parsing

 
import sys
from xml.sax import saxutils
from xml.sax import make_parser
from xml.sax import handler

class SimpleHandler(saxutils.DefaultHandler):
    def startElementNS(self,name,qname,attrs):
        print 'startElementNS: ', name,qname
        for n in attrs.getNames():
            print "  attribute :", n, attrs.getValue(n)
          
    def endElementNS(self,name,qname):
        print 'endElementNS: ', name, qname

parser = make_parser()
sh = SimpleHandler()
parser.setContentHandler(sh)
parser.setFeature(handler.feature_namespaces,1)
parser.parse(sys.argv[1])

   
  








Related examples in the same category

1.SAX-Based Analysis of the Guacamole Recipe
2.Structure of a Program to Process a Document with a _DTD Using SAX
3.Simple Use of Locator Object Methods