python中用xml.dom.minidom来解析xml文件件
在python中如何来解析xml文件件呢,我们来看看下面的示例,也许你就明白了
#coding=utf-8from xml.dom import minidomdoc = minidom.parse("web.xml")root = doc.documentElementnodes= root.getElementsByTagName("uu")for n in nodes: print n.getAttribute("value") #获取属性值 print n.childNodes[0].data #获取文本值存成一个文件件,试试,看以能不能获取到值
如果还想调用上面中的n的其它值,可以用查看这过程中产生的变量名来调用,这个有些编辑器会有,比如PyScripter就有,非常好用,朋友们不妨去试试.