文件名称:xml_AOI -1.7z
文件大小:16KB
文件格式:7Z
更新时间:2024-04-21 09:03:20
串流
import xml.etree.ElementTree as ET import traceback import pandas as pd import datetime filehoder=r'D:\myproject_python\AOI\xml_AOI -1\xml_AOI' filename=['V-NC419764','V-NC420305','NC421886'] with open(r'D:\myproject_python\AOI\xml_AOI -1\xml_AOI\0_V-NC419764.txt',"r") as f: file_section_list=f.read() f.close() print(file_section_list) def cutXmlSentences(file_str): """ 说明:一个xml文件中包含多个html段,进行分割. :param file: :return: """ final_list = [] output = "" str_list = file_str.split("\n") for i in range(len(str_list)): if str_list[i] != "\n": output += str_list[i] else: final_list.append(output) output = "" final_list.append(output) tmp_list = list(filter(lambda s: s != '' and s != ' ' and s != '\n', final_list)) return tmp_list def traversexml(element): """ 说明:遍历element所有子节点. :param element: :return: """ # print (len(element)) if len(element) > 0: for child in element: print(child.tag, "----", child.attrib) traversexml(child) def ReadXml(xml_string): """ 说明:解析xml文件成root. :param xml_string: :return: """ root = None if (xml_string): try: # print("xmlstring provided") root = ET.fromstring(xml_string) except Exception: # as e: print(xml_string) print("parse xmlstring failed!") finally: return root child_root = ReadXml(file_section_list) final_data_dict = {} for header in child_root.findall('header'): #这些元素只出现一次 for serialnumber in header.findall("serialnumber"): final_data_dict['boardid'] = serialnumber.text.strip("V-") for dt in header.findall("datetime"): date_time = datetime.datetime.strptime(dt.text.replace(".000+08:00", "").replace("T", " "),"%Y-%m-%d %H:%M:
【文件预览】:
xml_AOI
----19_V-NC420305.txt(2KB)
----0_V-NC419764.docx(17KB)
----0_V-NC419764.txt(3KB)
----27_V-NC421886.txt(2KB)
----1_V-NC419764.txt(3KB)
----11_V-NC420305.txt(3KB)
----10_V-NC420305.txt(3KB)
----18_V-NC420305.txt(3KB)
----7_V-NC419764.txt(3KB)
----21_V-NC420305.txt(3KB)
----13_V-NC420305.txt(3KB)
----6_V-NC419764.txt(3KB)
----29_V-NC421886.txt(2KB)
----17_V-NC420305.txt(3KB)
----9_V-NC419764.txt(2KB)