Mule 如何按名称获取所有XML节点?
我有这样的输入XML-Mule 如何按名称获取所有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"> <
<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="aaa" action="None">
<Attribute name="xxx">2</Attribute>
</grandChild>
</grandChild>
<grandChild name="ddd" action="None">
<Attribute name="xxx">1</Attribute>
<grandChild name="aaa" action="None">
<Attribute name="xxx">3</Attribute>
</grandChild>
</grandChild>
</child>
</parent>
这将使用..*选择器返回所需的输出,以检索所有子项并重建输出结构:
%dw 2.0
output application/xml
---
grandChilds:{
( payload.parent..*grandChild filter($.@name == 'aaa') map(gc) ->{
grandChild @(name: gc.@name, action: gc.@action): {
Attribute @(name: gc.Attribute.@name): gc.Attribute
}
})
}
产出:
<?xml version='1.0' encoding='UTF-8'?>
<grandChilds>
<grandChild name="aaa" action="None">
<Attribute name="xxx">1</Attribute>
</grandChild>
<grandChild name="aaa" action="None">
<Attribute name="xxx">2</Attribute>
</grandChild>
<grandChild name="aaa" action="None">
<Attribute name="xxx">3</Attribute>
</grandChild>
</grandChilds>
<?xml version='1.0' encoding='UTF-8'?>
<grandChilds>
<grandChild name="aaa" action="None">
<Attribute name="xxx">1</Attribute>
</grandChild>
<grandChild name="aaa" action="None">
<Attribute name="xxx">2</Attribute>
</grandChild>
<grandChild name="aaa" action="None">
<Attribute name="xxx">3</Attribute>
</grandChild>
</grandChilds>