I'm trying to parse xml, but am missing something. In the following, I can get the key, but not the value
from xml.dom import minidom
xmlstring = '''<search ver="3.0">
<loc id="USAR0433" type="1">Paris, AR</loc>
<loc id="USID0192" type="1">Paris, ID</loc>
</search>'''
dom = minidom.parseString(xmlstring)
r = dom.getElementsByTagName('search')[0]
res = []
for x in r.childNodes:
v = x.toxml()
for j in x.childNodes:
k = j.nodeValue
res.append({k:v})
for r in res:
for k,v in r.items():
print(k + ': ' + v)
which results in:
Paris, AR: <loc id="USAR0433" type="1">Paris, AR</loc>
Paris, ID: <loc id="USID0192" type="1">Paris, ID</loc>
I'd like to extract "USAR0433".
I could easily get it with re or string parsing, but wonder what minidom function to use to retrieve it. Parsing the string from toxml() seems to be cheating.