python 实现xml的解析
from xml.dom import minidomimport osdef parse_svcfile(svc_file): xmldoc = minidom.parse(svc_file) params = xmldoc.getElementsByTagName('param') procName = '' depends = '' for param in params: #print param.toxml() #print param.attributes['name'].value if 'svcagent' == param.attributes['name'].value: aa = param.childNodes for a in aa: procName = a.nodeValue continue if 'dependency' == param.attributes['name'].value: aa = param.childNodes #print aa.length for a in aa: depends = a.nodeValue print procName + ',' + dependsif __name__ == '__main__': files = os.listdir('a') #print files for file in files: if file.endswith('_svc.xml'): parse_svcfile('a/' + file)