1
votes

I have a soap testStep in SOAPUI with an XQuery match.

The XML (simplified) look as follows:

<root>
    <element>
        <a>a</a>
        <b>b</b>
        <c>c</c>
        <d>d</d>
    </element>
</root>

I want to make an XQuery to get all child nodes from <element> removing a child element depending on his node name. My XQuery looks like:

for $x in //root/element/element()
return 
if (name($x) != 'a') then $x
else ""

I expect the next result:

<b>b</b>
<c>c</c>
<d>d</d>

I think that my XQuery is correct, I tested with an XQuery online evaluator and looks ok, you can try with the follow link

However when I use this expression in a XQuery Match assertion in SOAPUI I get the following message: More than one match in current response. How can achieve this with SOAPUI?

Thanks,

1
How about simply using the XPath expression //root/element[local-name() != 'a']? - Marcus Rickert
@MarcusRickert thanks for the answer, but [local-name() != 'a'] is applying to the parent not to the child nodes, the SOAPUI is returning <element> <a>a</a> <b>b</b> <c>c</c> <d>d</d> </element> to your XPath. If I change your XPath's suggestion to //root/element/node()[local-name() != 'a'] in a XPath tester I get the desired result however SOAPUI returns again: "More than one match in current response". - albciff
You're right. I meant to write //root/element/*[local-name() != 'a']. Are you only allowed to have one root node in your XPath result? - Marcus Rickert
Thanks again @MarcusRickert but finally I found a solution :). - albciff
Your answer coincided with my remark. However, I still think that you can simplify your answer using my suggestion. - Marcus Rickert

1 Answers

1
votes

Doing some tries finally I found the solution, the way to do this XQuery in SOAPUI is specifying a root node in the XQuery expression i.e:

<MyResult>
{
for $x in //root/element/element()
return 
if (name($x) != 'a') then $x
else ""
}
</MyResult>