0

输入文件是-

<A>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>1000</amount>
    <currency_code>CAD</currency_code>
  </B>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>2000</amount>
    <currency_code></currency_code>
  </B>
  <B/>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>4000</amount>
    <currency_code></currency_code>
  </B>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>5000</amount>
    <currency_code></currency_code>
  </B>
</A>

尝试在 dataweave 中使用以下代码进行映射

 %output application/xml
    ---
    Inquiry: payload.A.*B mapObject
        {
        	balanceInquiry:
               { 
               	request: {
                    amount:{
                    amount: payload.A.B.amount/1000 as :number,            
                    currency: payload.A.B.currency_code
                           }
                         }
               }
         }

我正在尝试映射 A 下的 B 的每个值,但每次我得到相同的第一件事 5 倍于金额 1.0 是否应该更改为 2.0 4.0 和 5.0

请纠正我如果我做错了什么来实现 B 的所有值

4

2 回答 2

0

我没有更多地了解为什么 $.amount 无法访问,但对代码进行一些更改会使其工作。检查下面 -

%dw 1.0
%output application/xml
---
{
 Inquiry: payload.A.*B mapObject
    {
        balanceInquiry:
           { 
            request: {
                amount:{
                amount: ($[5]/1000 when $[5] != null otherwise 0) as :number,            
                currency: payload.A.B.currency_code
                       }
                     }
           }
     }
}

输出看起来像 -

<?xml version='1.0' encoding='windows-1252'?>
<Inquiry>
  <balanceInquiry>
    <request>
      <amount>
        <amount>1.0</amount>
        <currency>CAD</currency>
      </amount>
    </request>
  </balanceInquiry>
  <balanceInquiry>
    <request>
      <amount>
        <amount>2.0</amount>
        <currency>CAD</currency>
      </amount>
    </request>
  </balanceInquiry>
  <balanceInquiry>
    <request>
      <amount>
        <amount>0</amount>
        <currency>CAD</currency>
      </amount>
    </request>
  </balanceInquiry>
  <balanceInquiry>
    <request>
      <amount>
        <amount>4.0</amount>
        <currency>CAD</currency>
      </amount>
    </request>
  </balanceInquiry>
  <balanceInquiry>
    <request>
      <amount>
        <amount>5.0</amount>
        <currency>CAD</currency>
      </amount>
    </request>
  </balanceInquiry>
</Inquiry>
于 2016-03-17T14:41:39.617 回答
0

如果使用 mapObject 且未定义参数(键和值),则应使用其默认值。默认情况下,键定义为$$,值定义为$

因此,(部分)DataWeave 代码应该是:

amount: $.amount / 1000 as :number when $.amount != null otherwise 0,
currency: $.currency_code default ""
于 2016-03-17T07:56:56.810 回答