I am getting the following XML response back from a third-party vendor. I need to test if the value of ResponseCode is Success or Failure. If it is Success, I need to get the value of a:SessionToken and populate a property called session_token. How do I do that? None of the XPath expressions I have tried in my switch statement gave me access to the value of ResponseCode.
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<LoginResponse xmlns="www.mylocation.com/Order/v1">
<LoginResult xmlns:a="http://schemas.datacontract.org/2010/01/MyStuff.Responses" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Messages xmlns="http://schemas.datacontract.org/2010/01/MyStuff.Responses.Base" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:string>Login Successful</b:string>
</Messages>
<ResponseCode xmlns="http://schemas.datacontract.org/2010/01/MyStuff.Responses.Base">Success</ResponseCode>
<a:SessionToken>a4478-555d5-12rd-8989-jd776smjk</a:SessionToken>
</LoginResult>
</LoginResponse>
</s:Body>
</s:Envelope>
</soapenv:Body>
</soapenv:Envelope>
Current version of my switch:
<switch source="//ResponseCode/text()" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<case regex="Success">
<property expression="//a:SessionToken" name="session_token" scope="default" type="STRING" xmlns:a="http://schemas.datacontract.org/2010/01/MyStuff.Responses" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.datacontract.org/2010/01/MyStuff.Responses.Base" xmlns:v1="www.mylocation.com/Order/v1"/>
</case>
<case regex="Failure">
<property expression="body" name="_payload" scope="default" type="OM" xmlns:a="http://schemas.datacontract.org/2010/01/MyStuff.Responses" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.datacontract.org/2010/01/MyStuff.Responses.Base" xmlns:v1="www.mylocation.com/Order/v1"/>
</case>
<default>
<log>
<property name="session_token" value="No valid response found"/>
</log>
</default>
</switch>
PS: Namespaces have been changed to protect the innocent.
I think you should add in source xpath the namespace of that ResponseCode
node, so it could look like below:
<switch source="//dc:ResponseCode/text()" xmlns:dc="http://schemas.datacontract.org/2010/01/MyStuff.Responses.Base" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">