# -*- coding: utf-8 -*-
import xml.dom.minidom
import re
def Modify_file(Modify_deviceAnalog):
dom = xml.dom.minidom.parse(Modify_deviceAnalog)
root = dom.documentElement
deviceAnalogs = root.getElementsByTagName('AnalogGroup')
for Node in deviceAnalogs:
if Node.nodeType == Node.ELEMENT_NODE:
Type = Node.getAttribute('Type')
if Type == 'CSM_AC_CURVE':
for Node_ in (Node.childNodes):
if Node_.nodeType == Node_.ELEMENT_NODE:
No = Node_.getAttribute('No')
keys = ['\"'+str(i) +'\"' for i in range(100)]
values = ['\"'+str(i+1) +'\"' for i in range(100)]
replace_dict = dict(zip(keys,values))
def replace(match):
return replace_dict[match.group(0)]
No = re.sub('\"\d\"',replace,No)
# No(int("0")+1)
# list(int("0")+1,str([1234][0]))
newxml = file(Modify_deviceAnalog, 'w')
writer = codecs.lookup('utf-8')[3](newxml)
root.writexml(writer,addindent=' ', newl='', encoding='utf-8')
writer.close()
stationlist = ["BBS","YCD","BSZ",
"Z11","Z12","Z13"]
for station in stationlist:
Modify_deviceAnalog = u"D:/project/成渝线/现场配置数据/DataConf/"+ station + "/deviceAnalog.xml"
Modify_file(Modify_deviceAnalog)
print station