【问题标题】:DataWeave transformation issue in esb muleesb mule 中的 DataWeave 转换问题
【发布时间】:2015-12-21 00:57:45
【问题描述】:

我在 dataweave 中进行了转换。

我正在从 Mysql 数据库获取输入。输入有效载荷类型是 List-Map。我的 dataweave 编辑器有以下代码。

%dw 1.0
%namespace ns1 urn:abc:api:Components
%output application/xml 
---
ns1#"ItemRequest":{
    ns1#"Requester":
        ns1#ac: payload.time_max,

        ns1#"ErrorLanguage": "en_US",
        ns1#"WarningLevel": "High"
}

我的输出是

<?xml version='1.0' encoding='UTF-8'?>
<ns1:ItemRequest xmlns:ns1="urn:abc:api:Components">
  <ns1:Requester>
    <ns1:ac>
      <time_max>1</time_max>
    </ns1:ac>
  </ns1:Requester>
  <ns1:ErrorLanguage>en_US</ns1:ErrorLanguage>
  <ns1:WarningLevel>High</ns1:WarningLevel>
</ns1:AddItemRequest>

我不确定为什么要在输出中使用“time_max”在“ac”元素下创建标签。 'Time_max' 是 MySQL 表中的列名。但我不想在输出 xml 中添加列。我们怎样才能避免这种标签的创建?

预期输出是

<?xml version='1.0' encoding='UTF-8'?>
<ns1:ItemRequest xmlns:ns1="urn:abc:api:Components">
  <ns1:Requester>
    <ns1:ac>1</ns1:ac>
  </ns1:Requester>
  <ns1:ErrorLanguage>en_US</ns1:ErrorLanguage>
  <ns1:WarningLevel>High</ns1:WarningLevel>
</ns1:AddItemRequest>

【问题讨论】:

    标签: mysql mule esb dataweave


    【解决方案1】:

    我已经通过输入以下代码解决了这个问题。

    %dw 1.0
    %namespace ns1 urn:abc:api:Components
    %output application/xml 
    ---
    ns1#"ItemRequest":{
        ns1#"Requester":
            ns1#ac: payload[0].time_max,
            ns1#"ErrorLanguage": "en_US",
            ns1#"WarningLevel": "High"
    }
    

    下面的 sn-p 行很神奇。我已经包含了数组索引值。

     ns1#ac: payload[0].time_max
    

    【讨论】:

    • 看起来你的问题是输入是一个地图列表,我们经常从数据库连接器获得它的输出。假设输入是地图,则编写原始 DWL。也许将输入模式添加到未来读者的问题中?
    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    相关资源
    最近更新 更多