Forum Discussion

slaugier's avatar
slaugier
Occasional Contributor
6 years ago

How to get a string value from context.expand path with variables

Hi

 

I discover Groovy and the context.expand() way to find elements.

 

I want to get the value a:AccountTypeTextId=="LongTermLiquidity" as shown in this copyscreen below

 

If I execute this command , it works :

 LongTermLiquidity = new String (context.expand( '${GetHoldings#Response#declare namespace ns1=\'http://xxx.com/Schemas/yyy/Operations\'; declare namespace a=\'http://xxx.com/Schemas/yyy/Data/Advice\'; //ns1:GetHoldingsResponse[1]/ns1:GetHoldingsResult[1]/a:AccountDto[1]/a:AccountTypeTextId[1] }' ))

 

But if I execute this line, it doesn't work :

 LongTermLiquidity = new String (context.expand( '${GetHoldings#Response#declare namespace ns1=\'http://xxx.com/Schemas/yyy/Operations\'; declare namespace a=\'http://xxx.com/Schemas/yyy/Data/Advice\'; //ns1:GetHoldingsResponse[1]/ns1:GetHoldingsResult[@.a:AccountTypeTextId=="LongTermLiquidity"]/a:AccountDto[1]/a:AccountTypeTextId[1] }' ))

 

Can someone explain me how to deal with ns1:GetHoldingsResult[@.a:AccountTypeTextId=="LongTermLiquidity"] in order to get a valid result?

 

Thank you

 

Sylvain

  • nmrao's avatar
    nmrao
    Champion Level 3
    Would you please below xpath:

    //ns1:GetHoldingsResult/a:AccountDto[@.a:AccountTypeTextId=="LongTermLiquidity"]/a:AccountTypeTextId
    • slaugier's avatar
      slaugier
      Occasional Contributor

      Thank you for your answer, but it doesn't work.

       

      if I replace  //ns1:GetHoldingsResponse[1]/ns1:GetHoldingsResult[@.a:AccountTypeTextId=="LongTermLiquidity"]/a:AccountDto[1]/a:AccountTypeTextId[1] by //ns1:GetHoldingsResult/a:AccountDto[@.a:AccountTypeTextId=="LongTermLiquidity"]/a:AccountTypeTextId ,

      I still receive an empty string

       

      //ns1:GetHoldingsResult/a:AccountDto[1]/a:AccountTypeTextId doesn't work too

       

      the only one that works is //ns1:GetHoldingsResponse[1]/ns1:GetHoldingsResult[1]/a:AccountDto[1]/a:AccountTypeTextId[1]

      • nmrao's avatar
        nmrao
        Champion Level 3
        Put single equals instead of double (in the previous reply xpath) and retry.