xml文件
<?xml version="1.0" encoding="GBK"?> <records serial_number="1"> <record id="1" name="admin" password="admin" auth="1" email="" receivedMail="0" description="系统超级管理员,不能被删除。" createTime="N/A"/> </records>
python 脚本
#coding=utf-8 import xml.dom.minidom //格式转换 xml_file_string=open(‘/nasgui/share/user.xml‘,‘r‘).read() xml_file_string=xml_file_string.replace(‘<?xml version="1.0" encoding="GBK"?>‘,‘<?xml version="1.0" encoding="utf-8"?>‘) xml_file_string=unicode(xml_file_string,encoding=‘gbk‘).encode(‘utf-8‘); dom = xml.dom.minidom.parseString(xml_file_string) //获取根节点 root = dom.documentElement//获取记录 itemlist=root.getElementsByTagName(‘record‘) item=itemlist[0] un=item.getAttribute(‘name‘) print un
时间: 2024-12-12 05:04:25