from xml.dom import minidom
xmldoc = minidom.parse('emails.xml')
cNodes = xmldoc.childNodes
nList = cNodes[1].getElementsByTagName("to")
for node in nList:
eList = node.getElementsByTagName("addr")
for e in eList:
if e.hasAttribute("type"):
if e.getAttribute("type") == "TO":
print e.toxml()
nList = cNodes[1].getElementsByTagName("to")
for node in nList:
eList = node.getElementsByTagName("addr")
for e in eList:
if e.hasAttribute("type"):
if e.getAttribute("type") == "CC":
print e.toxml()
nList = cNodes[1].getElementsByTagName("to")
for node in nList:
eList = node.getElementsByTagName("addr")
for e in eList:
if e.hasAttribute("type"):
if e.getAttribute("type") == "BC":
print e.toxml()