1、获取suit1.cnf文件中“suit1的描述信息”部分的内容
from xml.dom import minidom
xmldoc = minidom.parse(“C:\\Users\\dell\\Desktop\\111\\suit1.cnf”)
print xmldoc.toxml()
for i in xmldom.childNodes[0].getElementsByTagName("description"):
print i.childNodes[0].toxml()
第二句代码得到一个Document类型变量xmldoc, 它是一个保存文档所有信息的树结构。用Node的toxml()函数可以得到节点中保存的xml字符串。因为Document是Node的子类,所以可以应用toxml函数
因为xmldoc元素有两个孩子结点,从0开始排。
2、
如果想要得到根元素,即suit1.cnf中的config
from xml.dom import minidom
xmldoc = minidom.parse(“C:\\Users\\dell\\Desktop\\111\\suit1.cnf”)
root = xmidoc.documentElement
print root
3、DOM是Document Object Model的简称,它是以对象树来表示一个XML文档的方法,使用它的好处是你可以非常灵活的在对象中进行遍历。
4、附录:suit.cnf
<?xml version="1.0" encoding="utf-8"?>
<config>
<description>su