0

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

例子:

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

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

4

1 回答 1

0

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

于 2019-11-28T16:20:03.297 回答