def createTLSXML(file, simulation_values, trafficLight_Input): top = Element('additional') parent_b = SubElement(top, 'tlLogic', id=str(simulation_values['tls_id'][0]), type=str(trafficLight_Input['type'].unique()[0]), programID='1', offset='0') children = [] for v in list(trafficLight_Input.T.to_dict().values()): c = XML( '''<phase duration="" state="" minDur="" maxDur="" name=""/> ''') if isInputNotNan(v['phaseDuration']): c.set('duration', str(v['phaseDuration'])) if isInputNotNan(v['state']): c.set('state', str(v['state'])) if isInputNotNan(v['minDur']): c.set('minDur', str(v['minDur'])) if isInputNotNan(v['maxDur']): c.set('maxDur', str(v['maxDur'])) if isInputNotNan(v['phaseDuration']): c.set('name', str(v['name'])) children.append(c) # children = [ # Element('phase', duration=str(v['phaseDuration']), state=str(v['state']), minDur=str(isInputNotNan(v['minDur'])), maxDur=str(v['maxDur']), name=str(v['state'])) # for v in list(trafficLight_Input.T.to_dict().values()) # ] parent_b.extend(children) # Copy nodes to second parent # print(prettify(top)) # os.makedirs(os.path.dirname(file), exist_ok=True) myfile = open(file, "w") myfile.write(prettify(top))