我的输入xml:
>>> 45 is greater than 21
我尝试过的数据编辑配置:
<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>
我的csv o / p:
%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"
}
要求很明确。我只需要元素记录[0]。我的o / p CSV不应该有空行。 预期输出应为:
id,type (headers)
blanklines
.
.
.
g,g
.
.
.
.
t,t
.
.
我仍然无法理解用于循环的dataweave的语法和概念。请帮帮我。接受任何更好的解决方案。
答案 0 :(得分:0)
如何访问名称属性(@name),因为它不在您的XML中? 你应该访问'att'属性吗? (@att)
您是否发布了正确的代码和XML?
好的,这应该可以帮到你。
%dw 1.0
%input payload application/xml
%output application/csv
---
payload.Root.*Element[0].*Record map {
(id:$.@att) ,
(type:$.@att)
} filter ($.id == "g" or $.type == "t")
答案 1 :(得分:0)
如果不使用下标,则引用第一个元素。您可以尝试删除下标[0]
%dw 1.0
%input payload application/xml
%output application/csv
---
payload.Root.*Element.*Record map {
(id:$.@att) ,
(type:$.@att)
} filter
答案 2 :(得分:-1)
以下代码可以正常使用
Weave Code
%dw 1.0
%output application/csv
---
payload.Root.*Element[0].*Record filter (($.@att == 'g') or ($.@att == 't')) map {
(id : $.@att),
(type : $.@att)
}
输出
id,type
g,g
t,t