Xml parsing using xml.dom
Question: My xmls aren't like others. Here is an example of my xml:

    
    
            "<msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg>"
    

what I want is to get the value of action. How do I do that using xml.dom in
python...


Answer: Here is the code that uses xml.dom and extracts value of action attribute:

    
    
    s = "<msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg>"
    
    from xml.dom import minidom
    
    el = minidom.parseString(s)
    
    el.getElementsByTagName('body')[0].attributes['action'].value
    Out[4]: u'verChk'
    

