python解析xml文件,代码如下:
import xml.dom.minidom as xmldomimport osxmlfilepath = os.path.abspath("E:/Lining_EC_WH_CHENGDU.xml")print("xml文件路径:", xmlfilepath)# 得到文档对象domobj = xmldom.parse(xmlfilepath)# print("xmldom.parse:", type(domobj))# 得到元素对象elementobj = domobj.documentElement# print("domobj.documentElement:", type(elementobj))#获得子标签subElementObj = elementobj.getElementsByTagName("skuCode")# print ("getElementsByTagName:", type(subElementObj))#区分相同标签名的标签subElementObj1 = elementobj.getElementsByTagName("skuCode")for i in range(len(subElementObj1)): # print ("subElementObj1[i]:", type(subElementObj1[i])) print (subElementObj1[i].firstChild.data) #显示标签对之间的数据print (len(subElementObj))复制代码