I want to parse this xml response with ILE RPG (Fully-Free RPG) in a data structure with a field for currency and a field for the value.
Thats my response from soap webservice:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCurrentExchangeRatesResponse xmlns="http://www.mnb.hu/webservices/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<GetCurrentExchangeRatesResult><MNBCurrentExchangeRates><Day date="2021-12-09"><Rate unit="1" curr="AUD">231,49</Rate><Rate unit="1" curr="BGN">187,05</Rate><Rate unit="1" curr="BRL">58,41</Rate><Rate unit="1" curr="CAD">254,93</Rate><Rate unit="1" curr="CHF">350,64</Rate><Rate unit="1" curr="CNY">50,92</Rate><Rate unit="1" curr="CZK">14,38</Rate><Rate unit="1" curr="DKK">49,20</Rate><Rate unit="1" curr="EUR">365,85</Rate><Rate unit="1" curr="GBP">426,84</Rate><Rate unit="1" curr="HKD">41,45</Rate><Rate unit="1" curr="HRK">48,61</Rate><Rate unit="100" curr="IDR">2,25</Rate><Rate unit="1" curr="ILS">104,13</Rate><Rate unit="1" curr="INR">4,28</Rate><Rate unit="1" curr="ISK">2,48</Rate><Rate unit="100" curr="JPY">284,60</Rate><Rate unit="100" curr="KRW">27,50</Rate><Rate unit="1" curr="MXN">15,41</Rate><Rate unit="1" curr="MYR">76,66</Rate><Rate unit="1" curr="NOK">36,17</Rate><Rate unit="1" curr="NZD">219,85</Rate><Rate unit="1" curr="PHP">6,41</Rate><Rate unit="1" curr="PLN">79,17</Rate><Rate unit="1" curr="RON">73,91</Rate><Rate unit="1" curr="RSD">3,11</Rate><Rate unit="1" curr="RUB">4,39</Rate><Rate unit="1" curr="SEK">35,70</Rate><Rate unit="1" curr="SGD">236,93</Rate><Rate unit="1" curr="THB">9,66</Rate><Rate unit="1" curr="TRY">23,50</Rate><Rate unit="1" curr="UAH">11,93</Rate><Rate unit="1" curr="USD">323,22</Rate><Rate unit="1" curr="ZAR">20,47</Rate></Day></MNBCurrentExchangeRates></GetCurrentExchangeRatesResult>
</GetCurrentExchangeRatesResponse>
</s:Body>
</s:Envelope>
The currencies are separated just with <.
I tried it like this, but my variable xmlout is empty after the xml-into.
dcl-ds xmlout qualified;
Tempout char(2129);
END-DS;
xml-into xmlout %xml(postResult: 'case=any ns=remove allowextra=yes +
path=Envelope/Body/GetCurrentExchangeRatesResponse/GetCurrentExchangeRatesResult');
So how can I change or extend my to code to get all the currencies and their values into a structured ds?
For the first XML-INTO, code xmlout.TempOut instead of just xmlout. In the XML document, GetCurrentExchangeRatesResult doesn't match a data structure.
Then you'd need a second XML-INTO to parse the new XML document in xmlout.TempOut.
Something like this, although varchar is probably not the right data type for everything.
dcl-ds MNBCurrentExchangeRates qualified;
dcl-ds day;
date date(*iso);
num_rate int(10);
dcl-ds rate dim(500);
unit varchar(10);
curr varchar(10);
value varchar(20);
end-ds;
end-ds;
end-ds;
xml-into MNBCurrentExchangeRates
%xml(xmlout.Tempout
: 'case=any countprefix=num_ datasubf=value');
Tip: When developing a new XML-INTO, avoid using the allowextra or allowmissing options at first. Use a simplified version of the document without any extra or missing XML items until your data structure matches the XML document in general. If you code allowextra=yes or allowmissing=yes too soon, XML-INTO will accept almost anything without giving any error messages.