Get_NodeInfo.py
678 Bytes
from xml.dom import minidom
# 打开XML文件
dom = minidom.parse("class.xml")
root = dom.documentElement
# # 根据标签名称获取标签对象
# names = root.getElementsByTagName('name')
# ages = root.getElementsByTagName('age')
# cities = root.getElementsByTagName('city')
#
# # 分别打印显示XML文档标签对中的内容
# for i in range(4):
# print(names[i].firstChild.data)
# print(ages[i].firstChild.data)
# print(cities[i].firstChild.data)
# 获取属性
logins = root.getElementsByTagName('login')
for i in range(2):
username = logins[i].getAttribute('username')
password = logins[i].getAttribute('password')
print(username,password)