1 import xml.dom.minidom 2 3 dom = xml.dom.minidom.parse('test.xml') 4 5 6 7 cc=dom.getElementsByTagName('caption') 8 print(cc) 9 10 print(cc[0].getAttribute("username")) 11 12 print(cc[0].firstChild.data) 13 14 dd = cc[1].getElementsByTagName('item') 15 print(dd[0].firstChild.data)