学习python ElementTree
时间:2007-03-05 来源:maojj
import xml.etree.ElementTree
tree = xml.etree.ElementTree.ElementTree(file="C:\config.xml")
#tree.write("mx.xml")
#tree.write("kdk.xml","utf_8") elem = tree.getroot()
for aa in elem.getiterator("cfg"):
method = aa.find("ModifyMethod")
print method.text
dict = aa.find("ToBeModifiedSecion")
print dict.text
xml <config><cfg><ConfigurationFilename>C:\usr\local\gemini\mgw\etc\mgw.properties</ConfigurationFilename>
<ModifyMethod>replaceByKeyValue</ModifyMethod><ToBeModifiedSecion>{
"QUEUEMGR.maxdata":"20","QUEUEMGR.maxindexes":"1500",
"SIDELINEQUEUE.maxdata":"20","SIDELINEQUEUE.maxindexes":"1500"
}
</ToBeModifiedSecion></cfg><cfg><ConfigurationFilename>C:\usr\local\gemini\mgw\etc\mgw.properties</ConfigurationFilename><ModifyMethod>replaceByKeyValue</ModifyMethod><ToBeModifiedSecion> {
"QUEUEMGR.maxdata":"23330","QUEUEMGR.maxindexes":"1500",
"SIDELINEQUEUE.maxdata":"24440","SIDELINEQUEUE.maxindexes":"1500"
}
</ToBeModifiedSecion></cfg></config>
#tree.write("mx.xml")
#tree.write("kdk.xml","utf_8") elem = tree.getroot()
for aa in elem.getiterator("cfg"):
method = aa.find("ModifyMethod")
print method.text
dict = aa.find("ToBeModifiedSecion")
print dict.text
xml <config><cfg><ConfigurationFilename>C:\usr\local\gemini\mgw\etc\mgw.properties</ConfigurationFilename>
<ModifyMethod>replaceByKeyValue</ModifyMethod><ToBeModifiedSecion>{
"QUEUEMGR.maxdata":"20","QUEUEMGR.maxindexes":"1500",
"SIDELINEQUEUE.maxdata":"20","SIDELINEQUEUE.maxindexes":"1500"
}
</ToBeModifiedSecion></cfg><cfg><ConfigurationFilename>C:\usr\local\gemini\mgw\etc\mgw.properties</ConfigurationFilename><ModifyMethod>replaceByKeyValue</ModifyMethod><ToBeModifiedSecion> {
"QUEUEMGR.maxdata":"23330","QUEUEMGR.maxindexes":"1500",
"SIDELINEQUEUE.maxdata":"24440","SIDELINEQUEUE.maxindexes":"1500"
}
</ToBeModifiedSecion></cfg></config>
相关阅读 更多 +