Dighate
Dighate

Reputation: 91

Xquery Assertion for SoapUI multiple modes

I'm trying to create an assertion for a Response that needs to looks like this:

 <Names>          
  <NameList PropertyName="Record">
           <Names>
              <SimpleValue Value="Date :xx"/>
              <SimpleValue Value="Name :xx"/>           
           </Names>
        </NameList>
  <NameList PropertyName="Record">
           <Names>
              <SimpleValue Value="Date :xx"/>
              <SimpleValue Value="Name :xx"/>             
           </Names>
        </NameList>
 </Names>

The assertion should be an exact match.

I have come up with a Xquery Assertions that looks like this:

  declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
   <Names>
   {
   for $x in/Response/NameList/Names/NameList      
   return <NameList> {($x/@PropertyName)} 
   <Names>
    {
    for $x in/Response/NameList/Names/NameList/Names/SimpleValue
    return  <SimpleValue>{($x/@Value)} </SimpleValue>
    }
    </Names>
    </NameList>
    }
    </Names>

But, This returns the SimpleValue from every Names node under Namelist. And It looks like this:

   <Names>
    <NameList PropertyName="Record">
      <Names>
        <SimpleValue Value="Date:xx"/>
        <SimpleValue Value="Name:xx"/>
        <SimpleValue Value="Date:xx"/>
        <SimpleValue Value="Name:xx"/>
     </Names>
    </NameList>
   <NameList PropertyName="Record">
     <Names>
      <SimpleValue Value="Date:xx"/>
      <SimpleValue Value="Name:xx"/>
      <SimpleValue Value="Date:xx"/>
      <SimpleValue Value="Name:xx"/>
     </Names>
  </NameList>
 </Names>

Can you please help? Thanks

Upvotes: 0

Views: 731

Answers (2)

GeekChick
GeekChick

Reputation: 128

My pro license is currently expired so I can't test this, but I'm pretty sure you need to do something like this:

declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
<Names>
{
    for $x in/Response/NameList/Names/NameList      
    return <NameList> {($x/@PropertyName)} 
    <Names>
    {
        for $y in $x/Names/SimpleValue
        return  <SimpleValue>{($y/@Value)} </SimpleValue>
    }
    </Names>
</NameList>
}
</Names>

Upvotes: 0

wst
wst

Reputation: 11771

To constrain the output, refer to the variable in your outer loop:

{
for $y in $x/Names/SimpleValue
return  <SimpleValue>{($y/@Value)} </SimpleValue>
}

Upvotes: 3

Related Questions