def search_hierarchy(path, name_file): file_hierarchy = utility.readFileXML(path + "\\", name_file) diz_meters_hierarchy = {} for val in file_hierarchy.getElementsByTagName("Meter"): for localId in val.getElementsByTagName("LocalId"): print(val.toxml()[val.toxml().find("<Factor>") + 8:val.toxml().find("</Factor>")]) if (localId.toxml()[localId.toxml().find(">") + 1:localId.toxml().find(".")] not in diz_meters_hierarchy): diz_meters_hierarchy[localId.toxml( )[localId.toxml().find(">") + 1:localId.toxml().find(".")]] = [{ localId.toxml()[localId.toxml().find(".") + 1:localId.toxml().find("</LocalId>")] }] else: diz_meters_hierarchy[localId.toxml( )[localId.toxml().find(">") + 1:localId.toxml().find(".")]] += [{ localId.toxml()[localId.toxml().find(".") + 1:localId.toxml().find("</LocalId>")] }] break #for factor in val.getElementsByTagName("Factor"): # print(factor.toxml()) #def start(folder): '''
def searchMeters(): hierarchy = utility.readFileXML(hierarchyPath, name_file_hierarchy) count = 0 serial_number = "" dizMeters = {} for val in hierarchy.getElementsByTagName("Meter"): for localId in val.getElementsByTagName("LocalId"): if (localId.toxml()[localId.toxml().find(">") + 1:localId.toxml().find(".")] not in dizMeters): dizMeters[localId.toxml()[localId.toxml().find(">") + 1:localId.toxml().find(".")]] = [ localId.toxml().strip( "</LocalId>") ] else: dizMeters[localId.toxml()[localId.toxml().find(">") + 1:localId.toxml().find(".")]] += [ localId.toxml().strip( "</LocalId>") ] if (count == 0): for description in val.getElementsByTagName("Description"): serial_number = description.toxml().split("\n")[0].split( "=")[1] count += 1 return (dizMeters, serial_number)
def create_dict_xml(name_hierarchy): diz_xml = {} hierarchy = utility.readFileXML(hierarchyPath, name_hierarchy) for val in hierarchy.getElementsByTagName("Meter"): diz_xml[val.toxml()[val.toxml().find("<LocalId>") + 9:val.toxml( ).find("</LocalId>")]] = val.toxml()[val.toxml().find("<Name>") + 6:val.toxml().find("</Name>")] return (diz_xml)