我的输入xml:
<Root>
<Element>
<Record att="a">value</Record>
<Record att="b">value</Record>
.
.
<Record att="g">value</Record>
<Record att="h">value</Record>
.
.
<Record att="p">value</Record>
.
.
<Record att="t">value</Record>
.
.
<Record att="w">value</Record>
.
.
<Record att="z">value</Record>
</Element>
<Element>
<Record att="a">value</Record>
<Record att="b">value</Record>
.
.
<Record att="g">value</Record>
<Record att="h">value</Record>
.
.
<Record att="p">value</Record>
.
.
<Record att="t">value</Record>
.
.
<Record att="w">value</Record>
.
.
<Record att="z">value</Record>
</Element>
.
.
.
.
.
.
</Root>
我尝试的数据编织配置:
%dw 1.0
%input payload application/xml
%output application/csv
---
payload.root.*Element[0].*Record map {
(id:$.@att) when ($.@att) == "g" or ($.@att) == "t",
(type:($.@att) when ($.@att) == "g" or ($.@att) == "t"
}
o/pi 进入了我的 csv:
id,type (headers)
blanklines
.
.
.
g,g
.
.
.
.
t,t
.
.
要求很明确。我只需要 Element[0] 的记录。我的 o/p CSV 不应该有任何空行。预期输出应该是:
id,type
g,g
t,t
我仍然无法理解 dataweave 循环的语法和概念。请帮帮我。接受任何更好的解决方案。