cancel
Showing results for 
Search instead for 
Did you mean: 

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

Occasional Contributor

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

image.png

 

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

3 REPLIES 3
Community Hero

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

Would you please below xpath:

//ns1:GetHoldingsResult/a:AccountDto[@.a:AccountTypeTextId=="LongTermLiquidity"]/a:AccountTypeTextId


Regards,
Rao.
Occasional Contributor

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

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]

Highlighted
Community Hero

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

Put single equals instead of double (in the previous reply xpath) and retry.


Regards,
Rao.
Ask a SmartBear
Top Kudoed Authors