Forum Discussion

Paultje's avatar
Paultje
New Contributor
12 years ago

Problem with multiple return in XQuery Match Assertion

Currently I'm trying to make an XQuery Match assertion on the GetWeatherInformation operation of the Weather service (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL) that returns the WeatherIDs and the Descriptions.

This is the XML response of the GetWeatherInformation operation:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeatherInformationResponse xmlns="http://ws.cdyne.com/WeatherWS/">
<GetWeatherInformationResult>
<WeatherDescription>
<WeatherID>1</WeatherID>
<Description>Thunder Storms</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif</PictureURL>
</WeatherDescription>
<WeatherDescription>
<WeatherID>2</WeatherID>
<Description>Partly Cloudy</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL>
</WeatherDescription>
<WeatherDescription>
<WeatherID>3</WeatherID>
<Description>Mostly Cloudy</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/mostlycloudy.gif</PictureURL>
</WeatherDescription>
(...)
<WeatherDescription>
<WeatherID>35</WeatherID>
<Description>Snow, Blowing Snow, and Fog</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL>
</WeatherDescription>
<WeatherDescription>
<WeatherID>36</WeatherID>
<Description>Unknown Precipitation</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/na.gif</PictureURL>
</WeatherDescription>
<WeatherDescription>
<WeatherID>37</WeatherID>
<Description>AM CLOUDS</Description>
<PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL>
</WeatherDescription>
</GetWeatherInformationResult>
</GetWeatherInformationResponse>
</soap:Body>
</soap:Envelope>


This is the XQuery Match assertion I've made:

declare namespace test = 'http://ws.cdyne.com/WeatherWS/';
<Result>
{
for $z in //test:WeatherDescription
return (<WeatherID>{data($z/WeatherID)}</WeatherID>,<Description>{data($z/Description)}</Description>)
}
</Result>


And this is the result of that assertion (by clicking 'Select from current'):

<Result>
<WeatherID/>
<Description/>
<WeatherID/>
<Description/>
<WeatherID/>
<Description/>
(...)
<WeatherID/>
<Description/>
<WeatherID/>
<Description/>
<WeatherID/>
<Description/>
</Result>


Does anyone know what I've done wrong here?

Thanks for your help!

3 Replies

  • SiKing's avatar
    SiKing
    Community Expert
    I think you§re getting lost in the namespaces. The following seems to work

    <Result>
    {
    for $z in //*:WeatherDescription
    return (<WeatherID>{data($z/*:WeatherID)}</WeatherID>, <Description>{data($z/*:Description)}</Description>)
    }
    </Result>
  • nayerehgh's avatar
    nayerehgh
    New Contributor
    I have the same problem, please help me
    the XML response of service is like below:


    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:transferSummaryResponse xmlns:ns2="http://service.y.modern.t.com/">
    <return>
    <currency>IRR</currency>
    <transactions>
    <count>1</count>
    <totalAmount>10</totalAmount>
    <transactionStatus>READY_FOR_PROCESS</transactionStatus>
    </transactions>
    <transactions>
    <count>1</count>
    <totalAmount>20</totalAmount>
    <transactionStatus>SUSPENDED</transactionStatus>
    </transactions>
    </return>
    </ns2:reportAchTransferSummaryResponse>
    </S:Body>
    </S:Envelope>


    I use Xquery Match for assertion . and XQuery Expression has value


    declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
    declare namespace ns2='http://service.y.modern.t.com/';
    <Row>
    {
    for $z in //ns2:TransferSummaryResponse/return/transactions
    return data($z/ns2:totalAmount/text())
    }
    </Row>


    and code in the Expected Result


    <Row>10 20</Row>


    but i get the below error and assertion failed:



    XQuery Match Assertion failed for path [declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/'; declare namespace ns2='http://service.y.modern.t.com/'; { for $z in //ns2:TransferSummaryResponse/return/transactions return data($z/ns2:totalAmount/text()) } ] : Exception:org.custommonkey.xmlunit.Diff [different] Expected presence of child nodes to be 'true' but was 'false' - comparing at /Row[1] to at /Row[1]



    can anyone help me? please help me
    thank you