i have an xml as a response in Soap UI test step:
<body>
<car>
<color>green</color>
<nr>88</nr>
</car>
<car>
<color>yellow</color>
<nr>54</nr>
</car>
<car>
<color>red</color>
<nr>17</nr>
</car>
<car>
<color>green</color>
<nr>18</nr>
</car>
<car>
<color>yellow</color>
<nr>56</nr>
</car>
<car>
<color>red</color>
<nr>12</nr>
</car>
</body>
And i want to create an assertion that the response has colors: green, yellow, red (no matter how many).
I wrote XQuery assertion:
<Result>
{
for $z in //car
order by $z/color
return
<color>{data($z/color)}</color>
}
</Result>
and i get the result:
<Result>
<color>green</color>
<color>green</color>
<color>red</color>
<color>red</color>
<color>yellow</color>
<color>yellow</color>
</Result>
but i can't group it, because it doesn't matter for me how many matches of each color in response. I tried
<Result>
{
for $z in //car
group by $z/color
order by $z/color
return
<color>{data($z/color)}</color>
}
</Result>
but i get an error "Invalid XQuery expression" in SoapUI 5.7.0.
Is there any way to assert the existing of certain colors with XQuery in SoapUI 5.7.0 ?
I had to fix sample XML. It is not well-formed.
Please try the following.
XQuery
<Result>
{
for $z in distinct-values(/body/car/color)
order by $z
return <color>{$z}</color>
}
</Result>
Output
<Result>
<color>green</color>
<color>red</color>
<color>yellow</color>
</Result>