无法将多值选择器的结果传递给 CONTAINS 函数
Unable to pass result of multi value selector to CONTAINS fucntion
我有一个输入xml。我想评估一个条件,该条件使用 "contains" 函数为真或假。这里是输入 xml
<?xml version='1.0' encoding='UTF-8'?>
<root>
<order>
<items>155</items>
</order>
<order>
<items>30</items>
</order>
<order>
<items>15</items>
</order>
<order>
<items>5</items>
</order>
<order>
<items>4</items>
<items>7</items>
</order>
<order>
<items>1</items>
<items>3</items>
</order>
<order>
null
</order>
</root>
我想查询以上项目的天气值 xml 包含 3 或
不是。所以我尝试了这段代码。
%dw 1.0
%output application/xml
---
{
Orders : payload.root.*order mapObject (
doesItContains : $.*items contains "3"
)}
它给我这样的错误。
Type mismatch for 'contains' operator
found :null, :string
required :array, :any or
required :string, :string or
required
:string, :regex
但是当我这样尝试时,效果很好
{
Orders : payload.root.*order mapObject (
doesItContains : $ mapObject (
contains3: $ contains "3"
)
)
}
它给出了预期的输出。
<?xml version='1.0' encoding='UTF-8'?>
<Orders>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>true</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
<contains3>true</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
</Orders>
我不知道为什么第一个代码不起作用。有人可以解释为什么第一部分代码不起作用
这是因为您的输入负载有<order>null</order>
。它没有 <items>
标签。您可以通过显示 $.*items
:
来看到这一点
%dw 1.0
%output application/xml
---
{
Orders : payload.root.*order mapObject (
test: $.*items
)}
输出:
<?xml version='1.0' encoding='UTF-8'?>
<Orders>
<test>
<items>155</items>
</test>
<test>
<items>30</items>
</test>
<test>
<items>15</items>
</test>
<test>
<items>5</items>
</test>
<test>
<items>4</items>
<items>7</items>
</test>
<test>
<items>1</items>
<items>3</items>
</test>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</Orders>
我有一个输入xml。我想评估一个条件,该条件使用 "contains" 函数为真或假。这里是输入 xml
<?xml version='1.0' encoding='UTF-8'?>
<root>
<order>
<items>155</items>
</order>
<order>
<items>30</items>
</order>
<order>
<items>15</items>
</order>
<order>
<items>5</items>
</order>
<order>
<items>4</items>
<items>7</items>
</order>
<order>
<items>1</items>
<items>3</items>
</order>
<order>
null
</order>
</root>
我想查询以上项目的天气值 xml 包含 3 或 不是。所以我尝试了这段代码。
%dw 1.0
%output application/xml
---
{
Orders : payload.root.*order mapObject (
doesItContains : $.*items contains "3"
)}
它给我这样的错误。
Type mismatch for 'contains' operator
found :null, :string
required :array, :any or
required :string, :string or
required
:string, :regex
但是当我这样尝试时,效果很好
{
Orders : payload.root.*order mapObject (
doesItContains : $ mapObject (
contains3: $ contains "3"
)
)
}
它给出了预期的输出。
<?xml version='1.0' encoding='UTF-8'?>
<Orders>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>true</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
<contains3>false</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
<contains3>true</contains3>
</doesItContains>
<doesItContains>
<contains3>false</contains3>
</doesItContains>
</Orders>
我不知道为什么第一个代码不起作用。有人可以解释为什么第一部分代码不起作用
这是因为您的输入负载有<order>null</order>
。它没有 <items>
标签。您可以通过显示 $.*items
:
%dw 1.0
%output application/xml
---
{
Orders : payload.root.*order mapObject (
test: $.*items
)}
输出:
<?xml version='1.0' encoding='UTF-8'?>
<Orders>
<test>
<items>155</items>
</test>
<test>
<items>30</items>
</test>
<test>
<items>15</items>
</test>
<test>
<items>5</items>
</test>
<test>
<items>4</items>
<items>7</items>
</test>
<test>
<items>1</items>
<items>3</items>
</test>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</Orders>