我的xmls不像其他人。 这是我的xml的一个例子:
"<msg t='sys'><body action='verChk' r='0'><ver v='153' /></body></msg>"
我想要的是获得行动的价值。 我如何在python中使用xml.dom ...
答案 0 :(得分:0)
以下是使用xml.dom并提取action属性值的代码:
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'