How do I pull specific data value from a response message using XmlSlurper

Katalon Studio Version:
KSE 8.6.6, Build 208
Windows 11 Enterprise (64-bit)
Chrome Version: Version 119.0.6045.106 (Official Build) (32-bit)

Hello folks, the following works as expected.
My question is how would I pull the just the <OrderId> value “231031000173” from the orderReponse result? I have tried several things but no luck so far.
Thanks Dave

import groovy.xml.*

def data = """
<OrderResponse xmlns:ns2="http://tempuri.org/OrderTrace.xsd">
<OglReq>
<OrderType>NEW</OrderType>
<AccountId>Q5K1234E</AccountId>
<OrderId>231031000173</OrderId>
<Action>BUY</Action>
<Action_Fr>Acheter</Action_Fr>
<MKT_LMT>LMT</MKT_LMT>
<Symbol>T</Symbol>
<SecType>EQT</SecType>
<SecDescription>SOME CORP</SecDescription>
<SecDescription_Fr>SOME CORP</SecDescription_Fr>
<Quantity>100</Quantity>
<Price>10.00</Price>
<EstMktPrice>22.64</EstMktPrice>
<OptionCode></OptionCode>
<ExpiryType>GTD</ExpiryType>
<ExpiryType_Fr>GTD</ExpiryType_Fr>
<ExpiryDate>2023-10-19</ExpiryDate>
<Market>CDN_BMR</Market>
<Market_Fr>Canada</Market_Fr>
<Professional>P</Professional>
<CommissionCode>D</CommissionCode>
<PrefiguredCommission>8.75</PrefiguredCommission>
<Currency>CAD</Currency>
<ExchangeRateType>D</ExchangeRateType>
<LoanRate>0.7</LoanRate>
<BehalfOfCode>EF</BehalfOfCode>
<RRId>5K8X</RRId>
<NextDayInd>N</NextDayInd>
<ExceptionOrder>I</ExceptionOrder>
<ClientArea></ClientArea>
<Pass>1</Pass>
<TraderNote></TraderNote>
<IbCode>CDI</IbCode>
<FirmTraderId>CQ005FI</FirmTraderId>
<JitneyInd>N</JitneyInd>
<ConfirmFee>0.0</ConfirmFee>
<ExchangeFee>0.0</ExchangeFee>
<SecFee>0.0</SecFee>
<FreeTradePreviousCommission>0.0</FreeTradePreviousCommission>
<Misc2>0.00</Misc2>
</OglReq>
<OrderAmount>1000.0</OrderAmount>
<OrderStatus>T</OrderStatus>
<ErrMsgCount>2</ErrMsgCount>
<ErrMsgs>
<ErrNum>C2233</ErrNum>
<ErrLvl>5</ErrLvl>
<ErrMsg>cleared funds required for buying equities, funds clear May 4th</ErrMsg>
<ErrMsg_Fr>fonds compensés nécessaires à l'achat d'actions</ErrMsg_Fr>
</ErrMsgs>
<ErrMsgs>
<ErrNum>00000</ErrNum>
<ErrLvl>0</ErrLvl>
<ErrMsg>Order submitted successfully.</ErrMsg>
<ErrMsg_Fr>Fonction exécutée avec succès.</ErrMsg_Fr>
</ErrMsgs>
</OrderResponse>
"""

def slurper = new XmlSlurper()
def orderResponse = slurper.parseText(data)
println('orderResponse: ' + orderResponse)

Output: orderResponse: NEWQ5K1234E231031000173BUYAcheterLMT …

2 Likes

@Dave_Evers

It should be

println('orderId: ' + orderResponse.OglReq.OrderId)
3 Likes

Thanks, it works as expected

3 Likes