我有一个如下的 xml 文件:
<alarms rootMIB="1" source="PLATFORM">
<alarm alarmCode="123" alarmMIBName="chassde">
<alarmObject>CHASSIS</alarmObject>
<alarmType>equipmentAlarm</alarmType>
<probableCause>equipmentMalfunction</probableCause>
<description>Report</description>
</alarm>
</alarms>
我可以通过以下代码获取“alarmCode”和“alarmMIBName”的属性:
import xml.dom.minidom
for alarm_tag in dom.getElementsByTagName('alarm'):
if alarm_tag.hasAttribute('alarmMIBName'):
alarmmibname = str(alarm_tag.getAttribute('alarmMIBName'))
但我也想打印 hasAttribute 'alarmMIBName' 的整行,即这一行:
<alarm alarmCode="123" alarmMIBName="chassde">
谁能告诉我如何打印整行?非常感谢!