def func_parse_find_by_dict(self, root, dict_find): list_result=[] if 'dict_L2_find' in dict_find.keys(): List_node_L1 = self.func_ET_find_node_from_parent_node(root, dict_find, 'str_L1_findall', 'str_L1_find') list_L2_find_current = dict_find['dict_L2_find']['list_current'] for node_L1 in List_node_L1: list_L2_current_result = [self.func_ET_find_item_from_node(node_L1, str_t) for str_t in list_L2_find_current] # list_L2_L3_current_result = list_L2_current_result if 'dict_L3_find' in dict_find.keys(): List_node_L2 = self.func_ET_find_node_from_parent_node(node_L1, dict_find['dict_L2_find'], 'str_next_findall', 'str_next_find') list_L3_find_current = dict_find['dict_L3_find']['list_current'] if List_node_L2 == []: list_L3_current_result = ['--' for str_t in list_L3_find_current] list_result.append(list_L2_current_result + list_L3_current_result) else: for node_L2 in List_node_L2: list_L3_current_result = [self.func_ET_find_item_from_node(node_L2, str_t) for str_t in list_L3_find_current] if 'dict_L4_find' in dict_find.keys(): List_node_L3 = self.func_ET_find_node_from_parent_node(node_L2, dict_find['dict_L3_find'], 'str_next_findall', 'str_next_find') list_L4_find_current = dict_find['dict_L4_find']['list_current'] if List_node_L3 == []: list_L4_current_result = ['--' for str_t in list_L4_find_current] list_result.append(list_L2_current_result + list_L3_current_result + list_L4_current_result) else: for node_L3 in List_node_L3: list_L4_current_result = [self.func_ET_find_item_from_node(node_L3, str_t) for str_t in list_L4_find_current] list_result.append(list_L2_current_result + list_L3_current_result + list_L4_current_result) else: list_result.append(list_L2_current_result + list_L3_current_result) else: list_result.append(list_L2_current_result) list_result_key=[] if 'dict_L2_find' in dict_find.keys(): list_result_key = list(map(os.path.basename, dict_find['dict_L2_find']['list_current'])) if 'dict_L3_find' in dict_find.keys(): list_result_key += list(map(os.path.basename, dict_find['dict_L3_find']['list_current'])) if 'dict_L4_find' in dict_find.keys(): list_result_key += list(map(os.path.basename, dict_find['dict_L4_find']['list_current'])) return list_result,list_result_key
时间: 2023-05-22 12:06:52 浏览: 113
这段代码是一个函数,函数名为"func_parse_find_by_dict",他接受两个参数:一个是XML的根节点,一个是要查找的字典。函数的作用是从根节点开始查找符合字典中描述的要求的节点,并返回一个结果列表。
如果字典中包含键"dict_L2_find",则会先查找一级节点,然后再在一级节点下查找二级节点。函数会调用另外两个函数来完成这个任务,具体细节不在本段代码中体现。在找到符合要求的节点后,函数会根据字典中给出的要求提取节点中的内容,并将结果添加到一个结果列表中。
阅读全文