> Modules standards > Autres modules > Parsing SAX
Parsing SAX
Exemple :
import xml.sax
parser = xml.sax.make_parser()
myHandler = MyHandler()
parser.setContentHandler(myHandler)
parser.parse(myFile)
on peut aussi faire directement :
xml.sax.parse(myFile, myHandler)
Définition de la classe handler :
class MyHandler(xml.sax.ContentHandler):
def startDocument(self):
pass
def startElement(self, name, attrs):
keys = attrs.keys()
value = attrs.getValue('myAttributeName')
def endElement(self, name):
pass
def characters(self, content):
pass
Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert