python中xml解析

import xml.dom.minidom

input_xml_string = '''
<root>
<a>hello</a>
</root>
'''
#打开xml文档
#dom = xml.dom.minidom.parse(‘abc.xml‘)
dom=xml.dom.minidom.parseString(input_xml_string) #获得整个文档对象
root=dom.documentElement
print root.nodeName #节点名字
print root.nodeValue #节点值
print root.nodeType #节点类型

猜你喜欢

转载自www.cnblogs.com/hanjiajiejie/p/9167801.html