【发布时间】:2019-08-07 08:28:46
【问题描述】:
我有一个简单的 XML,其中包含像这样的嵌套 grandChild 节点
<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>
我只想提取所有 grandChild 节点的列表。我能够在迭代每个节点时实现,这给了我一个级别的列表,但不是整个 XML。有没有可能用单一的dataweave来实现?
我的简单数据编织看起来像这样
%dw 2.0
output application/json
---
payload.parent.child.*grandChild.*grandChild map {
"@name": $.@name,
"Attribute" : $.*Attribute map {
"@name" : $.@name,
"#text" : trim($)
}
}
期望的输出
[
{
"@name": "bbb",
"Attribute": [
{
"@name": "xxx",
"#text": "1"
}
]
},
{
"@name": "ccc",
"Attribute": [
{
"@name": "xxx",
"#text": "1"
}
]
},
{
"@name": "aaa",
"Attribute": [
{
"@name": "xxx",
"#text": "1"
}
]
},
{
"@name": "ddd",
"Attribute": [
{
"@name": "xxx",
"#text": "1"
}
]
}
]
【问题讨论】:
标签: anypoint-studio dataweave mule4