2023年6月25日发(作者:)
python遍历XMLinminidom# -*- coding: utf-8 -*-#!/usr/local/bin/pythonimport mimport pdbimport os#Read Node's TEXT_NODE value
def getText(nodelist):
rc = []
for node in nodelist:
if pe == _NODE: () #If it's need trim ,use follow sentance
#(().rstrip()) return ''.join(rc)#Input parameter : fileName
#Read XML file struct like this
'''
dom = (fileName)
urlDic = {} urlCategory = ''
urlValue = ''
for item in mentsByTagName("String"): if ribute("id"): #urlCategory ="[" + fileName[(""):len(fileName)-1] + "] " + utes["id"].value
urlCategory = utes["id"].value
urlValue = getText(odes) if len(urlValue) is not None or len(urlValue) > 0 : urlDic[urlCategory] = urlValue else :
print "ERROR :fileName[%s] t attributeValue[%s] t textNodeValue[%s] invalid"%(fileName,urlCategory,urlValue)
return urlDic
except:
print "loading file [%s]" % (fileName)
return None
if __name__ == "__main__":
urlDic = {} urlDicTMP = {} parentPath = "D:codeloadXMLFile" fileList = r(parentPath) for fileName in fileList :
urlDicTMP = getInfoFromFile(parentPath + "" + fileName) if urlDicTMP is None :
print "fileName :[%s] is None "%(fileName) continue
for key in urlDicTMP: #whether this value has been set in urlDic
if _key(key) :
print "WARNING : fileName[%s] t key[%s] has been set."%(fileName ,key) else : urlDic[key] = urlDicTMP[key]
print "-"* 70 for key in urlDic: print "%s === %s"%(key,urlDic[key])
#("%s === %s",key,urlDic[key])
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1687678443a30852.html
评论列表(0条)