<conf>
<server>
<active name="MyName">0</active>
<active name="MyName2">1</active>
<scripts>
</scripts>
</server>
</conf>
знаю что через XPath можно одной,двумя строками/командами обойтись.
а сейчас извращаюсь примерно так:
import xml.dom.minidom
g_hostlist = {}
def XMLgetText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
def LoadXMLClient():
try:
global g_hostlist
document = open('s1.xml','r').read()
dom = xml.dom.minidom.parseString(document)
doc = dom.getElementsByTagName("server")
for d in doc:
name = d.getElementsByTagName("active")
if len(name)>0:
if XMLgetText(name[0].childNodes)=='1':
iname = d.getElementsByTagName("name")
if len(iname)>0: name = XMLgetText(iname[0].childNodes)
ip = d.getElementsByTagName("ip")
if len(ip)>0: pp = XMLgetText(ip[0].childNodes)
pr = 8011
ip = d.getElementsByTagName("port")
if len(ip)>0:
try:
pr = int(XMLgetText(ip[0].childNodes))
except:
print 'Error port'
#print name,pp
g_hostlist[name] = {'ip':pp, 'port':pr}
return 1
except:
print 'Error XML pars'
return 0