""" This program is for processing the XML export from Bobby. Bobby is a software that can exam the accessiblity of a web page accoring to the rules defined by Web accessibility initiative and American Rahabilitation Act Section 508. The result of the programm list the url of the web page, the error id defined in Bobby's preference and the number of errors that Bobby has found. This can be used to measure the general web accessiblity of a web site. Author: Xiaoming Zeng Date: 2/1/2003 """ version = '0.1' from xml.sax.handler import ContentHandler import xml.sax import sys #=================================================== # # Count Handler subclass of ContentHandler # #=================================================== class countHandler(ContentHandler): #Construct of the class def __init__(self): self.tags={} #Page tag dictionary self.ids={} #Error ID dictionary self.url="" #Universal Resoruce Locator self.id = "" #Error ID self.count = 0 #Count for Page Number #Overload startElement method def startElement(self, name, attrs): if name=="page": self.url = attrs.get('url', "") if not self.tags.has_key(self.url): self.tags[self.url] = 0 self.tags[self.url] += 1 elif name=="error": self.id = attrs.get("id", "") if not self.ids.has_key(self.id): self.ids[self.id] = 0 self.ids[self.id] += 1 elif name=="instance": self.ids[self.id]+=1 #Overload endElement method def endElement(self, name): if name=="page": #Finish processing a page element self.count = self.count+1 print "Processing page ", self.count self.tags[self.url] = self.ids self.ids = {} #Clear ids dictionary elif name == "error": pass #====================================================== # #Output Result # #====================================================== parser = xml.sax.make_parser() handler = countHandler() parser.setContentHandler(handler) inputfile = raw_input('Enter input file name: ') parser.parse(inputfile) outputfilename = raw_input('Enter output file name: ') outputfile = open(outputfilename,'w') for eachKey in handler.tags.keys(): outputfile.write(eachKey + '\n') for eachKey2 in handler.tags[eachKey]: outputfile.write("\t " + eachKey2 + '\t:\t'+ str(handler.tags[eachKey][eachKey2]) + '\n') #print eachKey, handler.tags[eachKey] outputfile.close()