Accessing Element Attributes : DOM : XML PYTHON TUTORIALS


PYTHON TUTORIALS » XML » DOM »

 

Accessing Element Attributes


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()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo XML
» DOM