否则,数据编辑映射

时间:2016-03-16 14:38:57

标签: xml mule dataweave anypoint-studio

`输入: -

{"id":
{
 "items" : [
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "1000",
"currency_code": "CAD",
"token": {
  "token_type": "",
  "token_data": {
    "type": "",
    "value": "",
    "cardholder_name": "",
    "exp_date": ""
  }
},
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "2000",
"currency_code": "",
"token": {
  "token_type": "",
  "token_data": {
    "type": "",
    "value": "",
    "cardholder_name": "",
    "exp_date": ""
  }
},  
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "authorize",
"method": "token",
"order_number": "123",
"amount": "3000",
"currency_code": "",
"token": {
  "token_type": "",
  "token_data": {
    "type": "",
    "value": "",
    "cardholder_name": "",
    "exp_date": ""
  }
}

] } }`

输出: - 没有任何Null B,因为我需要在没有Null B的情况下根据此输出进行另一个映射



<A>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>balance_inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>1000</amount>
    <currency_code>CAD</currency_code>
    <token>
      <token_type></token_type>
      <token_data>
        <type></type>
        <value></value>
        <cardholder_name></cardholder_name>
        <exp_date></exp_date>
      </token_data>
    </token>
  </B>
  <B>
    <merchant_ref>icici</merchant_ref>
    <transaction_tag>sdfhisdb</transaction_tag>
    <transaction_type>balance_inquiry</transaction_type>
    <method>valuelink</method>
    <order_number>123</order_number>
    <amount>2000</amount>
    <currency_code></currency_code>
    <token>
      <token_type></token_type>
      <token_data>
        <type></type>
        <value></value>
        <cardholder_name></cardholder_name>
        <exp_date></exp_date>
      </token_data>
    </token>
  </B>
</A>
&#13;
&#13;
&#13;

使用下面的数据编辑来检查xml的内容,但是将输出作为null B,请建议如何避免这种情况。因为我需要为每个元素做另一点指向从xml到xml的映射,但是Mapping正在创建一个额外的映射,其中B也是null。

请建议如何避免此

&#13;
&#13;
%dw 1.0
%output application/xml
---

A: payload.id.*items mapObject
{
	
      	B:$  when $.method=="valuelink"      
      
      otherwise {
      	
      }
     }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

下面应该有效。请注意,B:$由()封装,这意味着,仅当&#39;当&#39;时才包含此属性。条件是真的。

%dw 1.0
%output application/xml
---
{
    A: payload.A.*B mapObject {
        (B:$) when $.method == 'valuelink'
    }
}