Python 使用minidom和etree从具有属性的嵌套xml中获取值
我有以下xml数据:Python 使用minidom和etree从具有属性的嵌套xml中获取值,python,lxml,minidom,Python,Lxml,Minidom,我有以下xml数据: <response> <status>ok</status> <message>Done</message> <local-data> <name> <attribute key="first">John</attribute> <attribute key="middle">Maveric
<response>
<status>ok</status>
<message>Done</message>
<local-data>
<name>
<attribute key="first">John</attribute>
<attribute key="middle">Maverick</attribute>
<attribute key="last">Doe</attribute>
<name>
</local-data>
</response>
好啊
多恩
约翰
特立独行的
雌鹿
如何使用minidom和任何其他方法从xml中提取“first”或“middle”的值 这段代码应该有帮助
dom1 = parseString(xml_text)
elements = dom1.getElementsByTagName("attribute")
for element in elements:
if element.getAttribute('key') == "first":
print(element.firstChild.nodeValue)