【问题标题】:how to iterate and filter over a xml tags and check the condition in dataweave function in mule如何迭代和过滤xml标签并检查mule中dataweave函数中的条件
【发布时间】:2017-02-20 16:29:47
【问题描述】:

Dataweave 的输入

  <root>
     <client>
       <name>abc<name>
       <status>success</status>
     </client>
     <client>
       <name>def<name>
       <status>success</status>
     </client>
     <client>
       <name>ghi<name>
       <status>success</status>
     </client>
     <client>
        <name>jkl<name>
        <status>failed</status>
     </client>
     <client>
        <name>mno<name>
        <status>success</status>
     </client>
</root>

预期输出:

<root>
  <clients>
    <name>abc<name>
    <name>def<name>
    <name>ghi<name>
    ........
  </clients>
    <status>false</status>  // if all status are success then true otherwise false
 </root>

在这里,我可以遍历每个 xml 标记并使用 dataweave 映射客户端标记下的名称值。但我必须为所有状态映射单个输出。 即当一切都成功时,我的状态将为 true ,如果任何一个状态为失败,我的状态将为 false。 为此,我们必须编写一个函数,该函数将遍历每个 xml 标记,并且必须根据条件返回输出 trur 或 false。

谢谢,

【问题讨论】:

    标签: mule dataweave


    【解决方案1】:

    过滤等于“失败”的状态列表。如果它没有返回记录,则意味着所有状态都是成功的,然后是 true。否则(返回多条记录)false。

    status: (sizeOf (payload.root.*client.status filter $ == "failed")) == 0
    

    或者

    status: not (payload.root.*client.status contains "failed")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-22
      • 2020-09-13
      相关资源
      最近更新 更多