Is there a way to parse a XML according to its attributes?

时间:2019-04-08 14:04:51

标签: python xml-parsing

I'm trying to parse my xml using minidom.parse but the program crushes when debugger reaches line xmldoc = minidom.parse(self)

Here is what have I tried:

attribValList = list()
xmldoc = minidom.parse(path)
equipments = xmldoc.getElementsByTagName(xmldoc , elementName)
equipNames = equipments.getElementsByTagName(xmldoc , attributeKey)
for item in equipNames:
    attribValList.append(item.value)

return attribValList

Maybe my XML is too specific for minidom. Here is how it looks like:

<TestSystem id="...">
    <Port>58</Port>
    <TestSystemEquipment>
        <Equipment type="BCAFC">
            <Name>System1</Name>
            <DU-Junctions>
                ...
            </DU-Junctions>
        </Equipment>

Basically I need to get for each Equipment its name and write the names into a list.

Can anybody tell what I'm doing wrong?

enter image description here

0 个答案:

没有答案