I'm trying to read this file if "TypeOfVessel" value is not null. list will be read if have "TypeOfVessel" value. Please see my code below. any suggestion please. Thanks
<ArrayOfConsolidatedList xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/">
<ConsolidatedList>
<RegimeName>Test1</RegimeName>
<Subsidiaries i:nil="true" />
<TonnageOfVessel i:nil="true" />
<TownOfBirth i:nil="true" />
<TypeOfVessel i:nil="true" />
</ConsolidatedList>
<ConsolidatedList>
<RegimeName>Test2</RegimeName>
<Subsidiaries i:nil="true"/>
<TonnageOfVessel>841</TonnageOfVessel>
<TownOfBirth i:nil="true"/>
<TypeOfVessel>Bunkering Vessel</TypeOfVessel>
</ConsolidatedList>
</ArrayOfConsolidatedList>
Python code:
import xml.etree.ElementTree as ET
import inspect
def ListParse():
tree = ET.parse('ListRead.xml')
root = tree.getroot()
all_entity_entries = root.find("{http://schemas.datacontract.org/2004/07/}ArrayOfConsolidatedList")
for entry in all_entity_entries:
RegimeName = entry.find('RegimeName').text
TonnageOfVessel = entry.find('TonnageOfVessel')
TypeOfVessel = entry.find('TypeOfVessel')
print(TypeOfVessel)
ListParse()
ListParse()does not return any value. Change the code and make it return what you need.matchesandcountry_listin the code? Clean the code, share the expected output and explain what is the problem