【问题标题】:How to combine map and a filter for an XML-attribute in dataweave 2.0?如何在 dataweave 2.0 中为 XML 属性组合映射和过滤器?
【发布时间】:2019-05-23 13:06:55
【问题描述】:

我试图从更大的集合中选择某个 XML,使用过滤器仅获取具有正确属性的 XML。

如果没有过滤器,我会收到当前集合中的所有最后一项,但无法为过滤器提供正确的语法...

我的 XML 数据:

<customer>
  <profile>
    <custom-attributes>
      <custom-attribute attribute-id="customerCredit">0.0</custom-attribute>
      <custom-attribute attribute-id="customerIDS">12345</custom-attribute>
      <custom-attribute attribute-id="sscid">00001</custom-attribute>
    </custom-attributes>
  /<profile>
</customer>

我的数据编织过滤器:

payload.ns0#customers.*ns0#customer map ( customer , indexOfCustomer ) -> {
    (customer.ns0#profile.*ns0#"custom-attributes" filter ($.ns0#"custom-attribute".@"attribute-id" == "customerIDS") map {
     "keys" : $
     }
     )      

我想收到上面示例的“keys: 12345”,但由于过滤器的原因,它被简单地跳过了。

【问题讨论】:

    标签: mule dataweave mule-esb


    【解决方案1】:

    您的输入与您的 dw 脚本不匹配,因此很难判断,没有命名空间并且缺少“客户”元素。

    但是根据您的输入和输出,您可以通过一个过滤器来实现它:

    %dw 2.0
    output application/json
    ---
    payload.*customer map {
        keys: $.profile."custom-attributes".*"custom-attribute" filter($.@"attribute-id"=="customerIDS")    
    }
    

    输出:

    [
      {
        "keys": [
          "12345"
        ]
      }
    ]
    

    或者根据你的例子,也不需要使用地图:

    %dw 2.0
    output application/json
    ---
    keys: payload.customer.profile."custom-attributes".*"custom-attribute" filter($.@"attribute-id"=="customerIDS")
    

    如果您提供更详细的输入和输出,您希望我们可以提供更多帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 2022-01-14
      相关资源
      最近更新 更多