4 def get_cycles(recipe_xml_filepath):
6 returns the number of cycles found in Recipe*.xml
8 handler = CycleXmlHandler()
9 sax.parse(recipe_xml_filepath, handler)
10 return handler.cycle_count
14 class CycleXmlHandler(sax.ContentHandler):
18 self.in_protocol = False
19 sax.ContentHandler.__init__(self)
22 def startDocument(self):
24 self.in_protocol = False
27 def startElement(self, name, attrs):
29 #Only count Incorporations as cycles if within
30 # the protocol section of the xml document.
31 if name == "Incorporation" and self.in_protocol:
32 #print 'Found a cycle!'
36 elif name == 'Protocol':
38 self.in_protocol = True
41 #print 'Skipping: %s' % (name)
44 def endElement(self, name):
46 if name == 'Protocol':
48 self.in_protocol = False