正在使用 RPG 和 HTTPLIB 解析 SOAP Web 服务的 XML 响应
Parsing XML response of SOAP web service with RPG and HTTPLIB
我想用 ILE RPG(完全免费的 RPG) 解析此 xml 响应,数据结构中有一个货币字段和一个值字段.
这是我从 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>
货币仅用<分隔。
我这样试过,但是我的变量 xmlout 在 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');
那么我如何更改或扩展我的代码以将所有货币及其价值放入结构化 ds 中?
对于第一个 XML-INTO,编码 xmlout.TempOut 而不仅仅是 xmlout。在 XML 文档中,GetCurrentExchangeRatesResult 与数据结构不匹配。
然后您需要第二个 XML-INTO 来解析 xmlout.TempOut 中的新 XML 文档。
类似这样,尽管 varchar 可能不是所有数据类型的正确数据类型。
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');
提示:在开发新的 XML-INTO 时,首先要避免使用 allowextra 或 allowmissing 选项。使用文档的简化版本,没有任何额外或缺少 XML 项,直到您的数据结构与 XML 文档大体匹配。如果您过早地编码 allowextra=yes 或 allowmissing=yes,XML-INTO 将接受几乎所有内容而不会给出任何错误消息。
我想用 ILE RPG(完全免费的 RPG) 解析此 xml 响应,数据结构中有一个货币字段和一个值字段.
这是我从 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>
货币仅用<分隔。
我这样试过,但是我的变量 xmlout 在 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');
那么我如何更改或扩展我的代码以将所有货币及其价值放入结构化 ds 中?
对于第一个 XML-INTO,编码 xmlout.TempOut 而不仅仅是 xmlout。在 XML 文档中,GetCurrentExchangeRatesResult 与数据结构不匹配。
然后您需要第二个 XML-INTO 来解析 xmlout.TempOut 中的新 XML 文档。
类似这样,尽管 varchar 可能不是所有数据类型的正确数据类型。
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');
提示:在开发新的 XML-INTO 时,首先要避免使用 allowextra 或 allowmissing 选项。使用文档的简化版本,没有任何额外或缺少 XML 项,直到您的数据结构与 XML 文档大体匹配。如果您过早地编码 allowextra=yes 或 allowmissing=yes,XML-INTO 将接受几乎所有内容而不会给出任何错误消息。