ok spent ages on this simple problem (I'm not good at XML) below code is probably self explanatory and it works, but i think this could be done a lot easier
Sample XML
<data>
<id name="ch01">
<channel>test channel 1</channel>
<gpio>3</gpio>
<cont>front</cont>
</id>
<id name="ch02">
<channel>test channel 2</channel>
<gpio>5</gpio>
<cont>back</cont>
</id>
</data>
The code used, which I eventually got working after reading a few posts on here:
from xml.dom import minidom
dom = minidom.parse('/usr/local/sbin/logger/chaninfo_test.xml')
id=dom.getElementsByTagName('id')
for node in id:
chanid=node.getAttribute('name')
print chanid
clist=node.getElementsByTagName('channel')
for c in clist:
print c.childNodes[0].nodeValue
glist=node.getElementsByTagName('gpio')
for g in glist:
print g.childNodes[0].nodeValue
colist=node.getElementsByTagName('cont')
for co in colist:
print co.childNodes[0].nodeValue
print
Can this be improved or cleaned up? The XML will increase in size but contents won't change, multiple IDs with one channel, gpis and cont field each.
The first thing that I'm thinking about is combining is and name is channel id='name', etc.