【问题标题】:Add incremented number in XML array using datawave 2.0 mule4?使用 dataweave 2.0 mule 4 在 XML 数组中添加增量数字?
【发布时间】:2019-11-29 16:58:21
【问题描述】:

如何在 mule4 中使用 datawave 2.0 在 XML 数组中添加递增的数字?

例子:

<Employees>    
    <Employee>    
        <Attribute Name="IncrementValue"></Attribute>    
    </Employee>    
    <Employee>    
        <Attribute Name="IncrementValue"></Attribute>    
    </Employee>    
<Employees>

以上示例使用序列号更新 IncrementValue。谁能帮帮我?

【问题讨论】:

    标签: dataweave mulesoft mule4


    【解决方案1】:

    DataWeave 是一种函数式语言。它没有计数器,但您可以为此 ejemlo 使用 mapObject() 函数的索引:

    %dw 2.0
    output application/xml
    ---
    Employees: payload.Employees mapObject((value1, key1, index1) ->
        Employee: value1 mapObject ((value2, key2, index2) -> (key2): index1) 
    )
    

    描述中输入的输出:

    <?xml version='1.0' encoding='UTF-8'?>
    <Employees>
      <Employee>
        <Attribute Name="IncrementValue">0</Attribute>
      </Employee>
      <Employee>
        <Attribute Name="IncrementValue">1</Attribute>
      </Employee>
    </Employees>
    

    索引从 0 开始。如果你想从 1 开始,你可以添加 1:index + 1

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 2021-02-23
    • 2021-10-27
    • 1970-01-01
    • 2020-03-27
    相关资源
    最近更新 更多