Python读取XML
来源:互联网 发布:js点击登录弹出登录框 编辑:程序博客网 时间:2024/06/06 04:38
#-*- coding:utf-8 -*-
from xml.etree import ElementTree
Service_Name='DMServices'
def read_xml(text):
# root = ElementTree.parse(r"D:/test.xml")
log = open('log.txt','w')
root = ElementTree.fromstring(text)
for node in root.findall("appSettings/add"):
if node.attrib.has_key("key") > 0 and node.attrib.has_key("value")>0 :
key = '%s' % node.attrib['key']
value = '%s' % node.attrib['value']
if key.find('Program.GroupProduction')>-1:
str = "%s\t%s" % (value, Service_Name)
print(str)
log.write(str)
log.write('\n')
log.flush()
log.close()
if __name__ == '__main__':
read_xml(open("test.xml").read())
from xml.etree import ElementTree
Service_Name='DMServices'
def read_xml(text):
# root = ElementTree.parse(r"D:/test.xml")
log = open('log.txt','w')
root = ElementTree.fromstring(text)
for node in root.findall("appSettings/add"):
if node.attrib.has_key("key") > 0 and node.attrib.has_key("value")>0 :
key = '%s' % node.attrib['key']
value = '%s' % node.attrib['value']
if key.find('Program.GroupProduction')>-1:
str = "%s\t%s" % (value, Service_Name)
print(str)
log.write(str)
log.write('\n')
log.flush()
log.close()
if __name__ == '__main__':
read_xml(open("test.xml").read())
阅读全文
0 0
- python读取xml字符串
- python读取xml脚本
- Python读取xml
- python 读取xml文档
- python读取xml文件
- python读取xml文件
- python读取xml文件
- python xml数据读取
- python读取xml文件
- python读取xml文件
- python读取xml文件
- python读取xml文件
- python读取xml数据
- python读取xml文件
- python读取xml文件
- python读取xml文件
- python读取xml
- python读取xml文件
- C语言:问题求解方法-穷举
- 备份和恢复MongoDB
- PHP魔术方法之构造方法__construct与析构方法__destruct
- 单点登录SSO的实现原理
- VIM命令
- Python读取XML
- c语言创建写入和读取TXT文件数据
- 松江1843路
- maven-in-five-minutes
- 关于XP\win7系统中安装.net4.0 程序运行版本出错的原因之一
- Android Wi-Fi wpa_cli与wpa_supplicant的交互
- PHP上传文件配置
- GIT 常用命令
- 印度1亿用户数据泄露 微软聚焦云业务拟裁员3000丨阿里云河南