Forum Discussion

mpw83's avatar
mpw83
Contributor
13 years ago

Select a spesific child node for given value

Hi All, I have a response like this..

<GetClientList>
<Client>
<ClientName>John</ClientName>
<ClientAddline1>1st Street</ClientAddline1>
<ClientAddline2>USA</ClientAddline2>
<ClientRole>PPR</ClientRole>
</Client>
<Client>
<ClientName>Sherry</ClientName>
<ClientAddline1>2st Street</ClientAddline1>
<ClientAddline2>MLB</ClientAddline2>
<ClientRole>QRP</ClientRole>
</Client>
<Client>
<ClientName>ASh</ClientName>
<ClientAddline1>3st Street</ClientAddline1>
<ClientAddline2>NYE</ClientAddline2>
<ClientRole>ZRP</ClientRole>
</Client>
</GetClientList>

I want to select the node <Client> which <ClientName> is 'Sherry' and assert all the values (including all the child elements) using XQuery assertion in SoapUI.

e.g \\GetClientList\Client\ClientName='Sherry' , \\GetClientList\Client\ClientAddline1='2st Street', \\GetClientList\Client\ClientAddline2='MLB' , \\GetClientList\Client\<ClientRole='QRP'

this can be done like this .. \\GetClientList\Client[3]\ClientName='Sherry' but the problem is its not always sorted as its displayed above,

Appreciated verify much your help ..

2 Replies

  • Hello,
    You can use xpath instead for each sub node that you want to assert.
    You can use following:
    //GetClientList/Client[./ClientName/text()=''Sherry"]/./ClientAddline1/text() to assert for Addline1
    Here is a more straightforward example:
    RESPONSE
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
    <a>
    <b>
    <c>abc</c>
    <c>wvu</c>
    <c>xyz</c>
    <c>qpo</c>
    </b>
    <b>
    <c>zyx</c>
    <c>wvu</c>
    <c>xxx</c>
    <c>qpo</c>
    </b>
    <b>
    <c>but_output_this</c>
    <c>wvu</c>
    <c>qpo</c>
    <c>looking_for_this</c>
    </b>
    <b>
    <c>axt</c>
    <c>wvu</c>
    <c>qpo</c>
    <c>zxz</c>
    </b>
    </a>
    </s:Body>
    </s:Envelope>


    XPATH EXPRESSION
    //a/b[./c='looking_for_this']/./c[1]

    XPATH RESULT
    but_output_this
    Hope it helps.
  • Hi Reshma , thanks for the help, it's worked :-)