如何分割Mule 4中的所有xml标记?

如何分割Mule 4中的所有xml标记?,mule,anypoint-studio,dataweave,mule4,Mule,Anypoint Studio,Dataweave,Mule4,我有一个输入xml,如下所示 <parent> <child type="reference"> <grandChild name="aaa" action="None"> <Attribute name="xxx">1</Attribute> <grandChild name="bbb" action="None"> &

我有一个输入xml,如下所示

<parent>
    <child type="reference">
        <grandChild name="aaa" action="None">
            <Attribute name="xxx">1</Attribute>
            <grandChild name="bbb" action="None">
                <Attribute name="xxx">1</Attribute>
            </grandChild>
            <grandChild name="ccc" action="None">
                <Attribute name="xxx">1</Attribute>
            </grandChild>
        </grandChild>
        <grandChild name="ddd" action="None">
                <Attribute name="xxx">1</Attribute>
        </grandChild>
    </child>
</parent>
我想将它拆分为多个XML,其中只有父->子->孙标记,因为有4个孙标记,所以上面的示例总共应该转换为4个XML。像这样-

<parent>
    <child type="reference">
        <grandChild name="aaa" action="None">
                <Attribute name="xxx">1</Attribute>
        </grandChild>
    </child>
</parent>

有人能在这方面指导我吗?我正在寻找Mule 3上的一些集合拆分器替代方案或任何其他可能的方法。

这将创建这些xml的数组,因此如果将此表达式放入foreach表达式中,它将满足您的需要

%dw 2.0
import dw::core::Objects

fun collectChilds(node) = do {
    var children = node.&grandChild default {}
    ---
    (children mapObject ((item, key) -> {
        parent: {
            child @("type": "reference") : {
                (key) : item.&Attribute
            }
        }
    }) pluck ((value, key, index) -> {(key) : value})
    ) ++ (Objects::valueSet(children) flatMap ((item, index) -> collectChilds(item)))
}
---
collectChilds(payload.parent.child)

嗨,谢谢你的回复。你有没有试着运行代码,它给我的错误是无法强制数组[{Attribute@name:xxx:1,孙子@name:bbb,action:None:{A…到mapObject的对象,因为mapObject需要一个对象,但我们有一个数组。我试着强制转换它,但它不起作用。我在Mule 4.1.3上
<parent>
    <child type="reference">
        <grandChild name="ccc" action="None">
                <Attribute name="xxx">1</Attribute>
        </grandChild>
    </child>
</parent>
<parent>
    <child type="reference">
        <grandChild name="ddd" action="None">
                <Attribute name="xxx">1</Attribute>
        </grandChild>
    </child>
</parent>
%dw 2.0
import dw::core::Objects

fun collectChilds(node) = do {
    var children = node.&grandChild default {}
    ---
    (children mapObject ((item, key) -> {
        parent: {
            child @("type": "reference") : {
                (key) : item.&Attribute
            }
        }
    }) pluck ((value, key, index) -> {(key) : value})
    ) ++ (Objects::valueSet(children) flatMap ((item, index) -> collectChilds(item)))
}
---
collectChilds(payload.parent.child)