I am currently working on IRC Bot and want to get the configuration from an XML file that looks like this:
<server> <host> HOST1 </host> <port> 6667 </port> <channel> <name> CHANNAME1</name> </channel> <channel> <name> CHANNAME2 </name> </channel> </server> <server> <host> HOST2 </host> <port> 6667 </port> <channel> <name> CHANNAME3 </name> </channel> </server>
And my code looks like this:
doc = minidom.parse(xml) node = doc.documentElement servers = doc.getElementsByTagName("server") for server in servers: channels = server.getElementsByTagName("channel") host = server.getElementsByTagName("host")[0].childNodes[0].data print host for channel in channels: NAME = channel.getElementsByTagName("name")[0].childNode[0].data print NAME
And conclusion
HOST1 CHANNAME1 CHANNAME2 CHANNAME3 HOST2 CHANNAME1 CHANNAME2 CHANNAME3
But I only need
HOST1 CHANNAME1 CHANNAME2 HOST2 CHANNAME3
Is there a way to get all elements with the tag name "channel" in my node server instead of the whole XML file?
user2153627
source share