Jun-19-2019, 06:43 AM
I tried to parse value in "programList/program"
<ns0:programList>
<ns0:program>FSE-IR</ns0:program>
</ns0:programList>
1. I managed to get value using follwing code. But is there a better way to get this?
1st try
Eg:
Appreciate if you can give some inputs to this.
<ns0:programList>
<ns0:program>FSE-IR</ns0:program>
</ns0:programList>
1. I managed to get value using follwing code. But is there a better way to get this?
1st try
for node in file.getroot(): for programList in node.findall('{http://tempuri.org/sdnList.xsd}programList'): for program in programList.findall('{http://tempuri.org/sdnList.xsd}program'): print(program.text)2nd try
def cleanaa(a): cleana = a[0] if a != [] else '' return cleana for node in file.getroot(): programList1 = cleanaa([[program.text for program in programList.findall('{http://tempuri.org/sdnList.xsd}program')] for programList in node.findall('{http://tempuri.org/sdnList.xsd}programList')]) print(programList1)The second output seems more appropriate as it creates a list and gets multiple values if there are many(maximum there can be two values) for each iteration.
Eg:
Output:['UKRAINE-EO13662']
['SYRIA', 'UKRAINE-EO13662']
['UKRAINE-EO13662']
2. Since there can be one or two values, can I get the two values into two variables, where if there is only one value the second variable will be an empty one? ('')Appreciate if you can give some inputs to this.