.xml文件内容:
4
Python测试Zope读取:
'''
读取.XML文件 树状结构
'''
#coding=utf-8
import xml.dom.minidom
# 打开xml文档
# dom = xml.dom.minidom.parse('./a.xml')
# 得到文档元素对象
# root = dom.documentElement
# 获得子标签 root.getElementsByTagName
# bb = root.getElementsByTagName('maxid')
# b = bb[0]
# print(b.nodeName)
#
# bb = root.getElementsByTagName('login')
# b = bb[0]
# print(b.nodeName)
#
# bb = root.getElementsByTagName('caption') # root.getElementsByTagName('caption') 获得的是标签为caption 一组标签,
b[0]表示一组标签中的第一个;b[2] ,表示这一组标签中的第三个
# b = bb[2]
# print(b.nodeName)
#
# bb = root.getElementsByTagName('item')
# b = bb[0]
# print(b.nodeName)
# 获得标签属性值 item.getAttribute
# dd = root.getElementsByTagName('login')
# dd = dd[0]
# d = dd.getAttribute('username')
# print(d)
# d = dd.getAttribute('passwd')
# print(d)
# 获得标签对之间的数据 c1.firstChild.data
# cc = root.getElementsByTagName('caption')
# c1 = cc[0]
# c = c1.firstChild.data
# print(c)
# c1 = cc[1]
# c = c1.firstChild.data
# print(c)
# c1 = cc[2]
# c = c1.firstChild.data
# print(c)