I am trying to get the value of status of response and available balance from xml returned from finacle core banking.
xml is at: https://pastebin.com/8bvpuUGp
I'm trying to get the value as below, but nothing appeared.
xroot = ET.fromstring(xml)
for ab in xroot.findall('AVAIL'):
bal = ab.find('AVAIL').text
print(bal)
CodePudding user response:
As far as I understand you want to get the balance for this 'AVAIL'
query.
You seem to be referring to a tag name, though it's a text contained within tag. Furthermore it does not have any child items, so your search does not work.
I'm not an expert in xml, but here is a working code I've come up with:
import re
import xml.etree.ElementTree as ET
term = 'AVAIL'
xroot = ET.fromstring(xml)
el = [element for element in xroot.iter() for child in element if child.text == term]
for i in [element for element in el[0].iter() if element.text != term]:
if len(i.text) > 1:
print(re.sub('{.*}', '', i.tag), i.text)
Otput:
amountValue 16299.37
currencyCode NPR
Here I find a child that contains text "AVAIL", than acsess a parent element and cycle though it's children to find everything except the query. Seems like this is the info you were looking for.