如何使用 mule 4 删除包含 id 的 DTOSteps 节点

How to remove the DTOSteps node which contains id using mule 4

我正在尝试删除包含 ID 属性的 DTOSteps 节点。

输入XML:

<?xml version="1.0" encoding="UTF-8"?>
<DTOApplication id="Application-1660258480-1493174910" ApplicationNumber="AP-00006354">
    <DTOLine id="Line-101746978-972142087" StatusCd="Active" >
        <DTOCoverage id="Coverage-1713637162-341585712" CoverageCd="MINP" >
            <DTOSteps>
                <DTOStep Order="1" Name="Premium"/>
                <DTOStep Order="2" Name="Term Factor">
                    <DTOSteps>
                            <DTOStep Order="1" Name="Minimum Premium" />
                            <DTOStep Order="2" Name="Rated Premium" />
                    </DTOSteps>
                </DTOStep>
            </DTOSteps>
        </DTOCoverage>
        <DTOCoverage id="Coverage-763105832-915106268" CoverageCd="TRIAL">
            <DTOSteps id="Steps-Coverage-763105832-915106268">
                <DTOStep id="Step-Coverage-763105832-915106268-Premium" Name="Premium" />
                <DTOStep id="Step-Coverage-763105832-915106268-TermFactor" Name="Term Factor"/>
            </DTOSteps>
        </DTOCoverage>
    </DTOLine>
    <DTOCoverage id="Coverage-763105832-915106268" CoverageCd="EBRK" >
        <DTOSteps id="Steps-Coverage-863105832-915106268">
            <DTOStep id="Step-Coverage-863105832-915106268-Premium" Name="Base Rate"/>
            <DTOStep id="Step-Coverage-863105832-915106268-TermFactor" Name="Term Factor"/>
        </DTOSteps>
    </DTOCoverage>
</DTOApplication>

我尝试了 dataweave 2.0,但它从输入中删除了所有 DTOSteps 节点 xml。

我的数据编织代码:

%dw 2.0
output application/xml

fun FNtransformCoverage(x, index)=
    x match {
      case is Object -> x mapObject 
        if ($$ as String == "DTOCoverage" )
            { 
                DTOCoverage @(( $$.@ )): $ - "DTOSteps"

            }
        else 
            (($$): FNtransformCoverage($, index+1)) 
      else -> $
    }
    
---
FNtransformCoverage(payload,1)

预期输出:https://github.com/Manikandan99/Map_request/blob/main/Transformed_output.xml

关于如何使用 dataweave 2.0 删除包含 id 的 DTOSteps 有什么想法吗?

您的脚本采用了正确的高级方法。它只需要使用 filterObject() 来删除元素。然后 mapObject 仅用于递归应用于嵌套元素。

%dw 2.0
output application/xml
fun FNtransformCoverage(x)=
    x match {
        case is Object -> 
            x 
                filterObject ((value, key, index) ->
                    key as String != "DTOSteps" or not (key.@id?))
                mapObject ($$):FNtransformCoverage($)
        else -> $
    }
---
FNtransformCoverage(payload)

输出:

<?xml version='1.0' encoding='UTF-8'?>
<DTOApplication id="Application-1660258480-1493174910" ApplicationNumber="AP-00006354">
  <DTOLine id="Line-101746978-972142087" StatusCd="Active">
    <DTOCoverage id="Coverage-1713637162-341585712" CoverageCd="MINP">
      <DTOSteps>
        <DTOStep Order="1" Name="Premium"/>
        <DTOStep Order="2" Name="Term Factor">
          <DTOSteps>
            <DTOStep Order="1" Name="Minimum Premium"/>
            <DTOStep Order="2" Name="Rated Premium"/>
          </DTOSteps>
        </DTOStep>
      </DTOSteps>
    </DTOCoverage>
    <DTOCoverage id="Coverage-763105832-915106268" CoverageCd="TRIAL"/>
  </DTOLine>
  <DTOCoverage id="Coverage-763105832-915106268" CoverageCd="EBRK"/>
</DTOApplication>

注意:您的预期输出中有重复的行。