xml 转换conf 基于python
来源:互联网 发布:微博刷粉软件ios 编辑:程序博客网 时间:2024/06/09 16:08
话部多说,xml格式如下:
<?xml version="1.0" encoding="UTF-8"?><conf><nova>192.168.0.1</nova><glance>192.168.0.2</glance><keystone>192.168.0.3</keystone></conf>
conf文件如下:
[service_ip_list]keystone = X.X.X.Xnova = Xglance = X
需要提取xml中的属性和值替换掉conf中的对应的配置,转换程序是用python写的
#-*-coding:utf-8-*-from xml.dom import minidomdoc = minidom.parse("conf.xml")conf_elements=doc.getElementsByTagName("conf")[0]nova=conf_elements.getElementsByTagName("nova")[0]#print nova.nodeName, nova.childNodes[0].nodeValueglance=conf_elements.getElementsByTagName("glance")[0]#print glance.nodeName, glance.childNodes[0].nodeValuekeystone=conf_elements.getElementsByTagName("keystone")[0]#keystone_ip=keystone.childNodes[0].nodeValue#print keystone.nodeName, keystone.childNodes[0].nodeValueimport ConfigParserimport string,os,syscf=ConfigParser.ConfigParser()cf.read("ip-list.conf")cf.set("service_ip_list","keystone",keystone.childNodes[0].nodeValue)cf.set("service_ip_list","nova",nova.childNodes[0].nodeValue)cf.set("service_ip_list","glance",glance.childNodes[0].nodeValue)fh=open("ip-list.conf",'w')cf.write(fh)fh.close()
0 0
- xml 转换conf 基于python
- python xml 转换csv ,csv 转换xml
- Python对象转换为xml
- CATALINA_HOME/conf/web.xml
- CATALINA_HOME/conf/web.xml
- sqlserve配置 conf.xml
- mysql配置 conf.xml
- 基于 minidom的python xml操作
- python操作conf配置文件
- Python xml和xsl转换为html
- Python 操作xml转换为json格式
- Tomcat/conf/server.xml配置
- Tomcat conf/servlet.xml 配置
- mybatis-conf.xml常用配置
- pom.xml和conf/settings.xml
- python读conf配置文件--ConfigParser
- python读conf配置文件--ConfigParser
- python读conf配置文件--ConfigParser
- Android* 操作系统上的应用程序远程调试
- MFC操作ini文件方法
- windows8+ubuntu12.04双系统安装方法
- 【框架-MFC】 CView 渐变颜色采样值(1)
- 【PyQt实例4】设置文体排序和对齐【转】
- xml 转换conf 基于python
- .NET过滤html标签
- 【编程好习惯】利用编程语言特性提高程序执行效率
- POJ2524 Ubiquitous Religions
- hashmap和hashtable的区别
- oracle数据库 sql%found,sql%notfound,sql%rowcount
- 我是个爱改Bug的程序员
- hdu1232 畅通工程
- HTML学习笔记