1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import sys, string
from xml.sax import ContentHandler, make_parser
class MonHandler(ContentHandler):
# un constructeur qui initialise plusieurs variables pour notre application #
def __init__(self,outfile):
self.outfile = outfile
self.level = 0
def startDocument(self):
print "--Debut Document--"
def EndDocument(self):
print "--Fin Document--"
def startElement(self, name, attributes):
self.level +=1
self.printLevel()
self.outfile.write('Element: %s\n ' %name)
self.level +=2
def endElement(self, name, attributes):
self.level -= 1
def characters(self, data):
pass
def printLevel(self):
self.outfile.write(' ')
def test(inFileName):
outFile = sys.stdout
handler = MonHandler(outfile) # creation d un exemple de déroulement (Handler)
parser = make_parser() # création d un analyseur syntaxique
parser.setContentHandler(handler)
inFile = open(inFileName , 'r')
parser.parse(infile)
inFile.close()
print 'offre-formation'
for formation in formationList:
prin ' %s' % (formation, )
def main():
args = sys.argv[1:]
if len(args) != 1:
print 'usage: python copieFichier.py base_offres.xml'
sys.exit(-1)
test(args[0])
if __name__ == '__main__':
main() |
Partager