Python解析xml中dom元素的方法
本文实例讲述了Python解析xml中dom元素的方法。分享给大家供大家参考。具体实现方法如下:
代码如下:
from xml.dom import minidom try: xmlfile = open("path.xml", "a+") #xmldoc = minidom.parse( sys.argv[1]) xmldoc = minidom.parse(xmlfile) except : #updatelogger.error( "Can't parse Xml File." ) sys.exit(0) ClientOutputPath = xmldoc.getElementsByTagName('D')[0].attributes['path'].value OutputPath = xmldoc.getElementsByTagName('h')[0].attributes['path'].value BasePath = xmldoc.getElementsByTagName('th')[0].attributes['path'].value ToolPath = xmldoc.getElementsByTagName('ub')[0].attributes['path'].value ToolPath_2 = xmldoc.getElementsByTagName('ub')[1].attributes['path'].value ClientOutputPath.replace( "\\", "\\\\" ) OutputPath.replace( "\\", "\\\\" ) BasePath.replace( "\\", "\\\\" ) ToolPath.replace( "\\", "\\\\" ) print ClientOutputPath print OutputPath print BasePath print ToolPath print ToolPath_2
希望本文所述对大家的Python程序设计有所帮助。
相关推荐
Yakamoz 2020-05-26
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
XGQ 2020-07-04
Andrewjdw 2020-05-29
行吟阁 2020-05-18
88491874 2020-04-30
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16