[XML-SIG] python xml

Lukasz Szybalski szybalski at gmail.com
Tue Mar 7 18:23:55 CET 2006

I am new to xml in python, but not new to python. After searching for 
quite a bit, I can't seem to find the answer to this easy coding problem.
I have a xml file that i need to find an element with id = 2 extract 
second child from it, and pass it on to the rest of my program.

How can i do it in "<10" lines of code in python?

<?xml version="1.0"?>
<response id="1">
                I'm out of office...etc..
<response id="2">
                I'm in the office...etc..

---python --
# I found most of the info/how to on minidom, so I assume minidom is the 
best choice here

from xml.dom import minidom, Node
#parse a file,
# find attribute

.....and here I find myself reading tons of how to, but can't seem to 
find what i'm looking for. .

#how can i do something like: (please correct me here)
 for x in  doc.nodeList:
    if x.attribute.get('id')==2:
       pass_it_on = ????      #How do I get to <text> and extract it as 

Thanks for the help

More information about the XML-SIG mailing list