我想对 XML 文件进行测试以查找缺少特定 TAG 的位置(TAG '终端'),但我的测试效果不佳
from xml.dom import minidom
xmldoc = minidom.parse('c:\\test\mydoc.xml')
#printing the number of blocs in my xml file
itemlist = xmldoc.getElementsByTagName('ACLineSegment')
print('************')
for s in itemlist :
if s.childNodes['Name'].value == 'Terminal':
print s.childNodes['Name'].value
这是我的 xml 文件的示例:
<ACLineSegment Name="T261" Description="" aliasName="">
<Link_Conducting PathB=""/>
<Terminal Name="T1" Description="" aliasName="">
<Link_Terminal PathB=""/>
</Terminal>
<Terminal Name="T2" Description="" aliasName="">
<Link_Terminal PathB=""/>
</Terminal>
</ACLineSegment>
<ACLineSegment Name="T262" Description="" aliasName="">
<Link_Conducting PathB=""/>
<Terminal Name="T1" Description="" aliasName="">
<Link_Terminal PathB=""/>
</Terminal>
<Terminal Name="T2" Description="" aliasName="">
<Link_Terminal PathB=""/>
</Terminal>
</ACLineSegment>
<ACLineSegment Name="T263" Description="" aliasName="">
<Link_Conducting PathB=""/>
</ACLineSegment>
enter code here