I have a payload in this format:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www...com/api/schemas/">
<soapenv:Header/>
<soapenv:Body>
<sch:GetAppointment>
From Apigee policy, I want to assign the method name "GetAppointment". For example I tried these:
<Variable name="methodname" type="string">
<XPath>//*[name(/soapenv:Body/*[1])]</XPath>
</Variable>
<Variable name="methodname" type="string">
<XPath>//*[name(/soapenv:Body/*[1])]</XPath>
</Variable>
I got a compilation error in both cases. I removed "soapenv:", but I could not get the child element name.
What is the XPath value I should use to extract "GetAppointment" in the above example. Or extract "sch:GetAppointment" so that I can parse it and get GetAppointment" eventually?
Solved! Go to Solution.
It works fine! I became able to assign the entity name. Thanks!
Usually when people use ExtractVariables on a SOAP document, it's the namespaces that trip them up. The key thing is: you've got to declare your namespaces explicitly in the EV policy. This works for me.
<ExtractVariables name='EV-SOAP-Operation'>
<Source>request</Source>
<VariablePrefix>soap</VariablePrefix>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<XMLPayload>
<Namespaces>
<Namespace prefix='soap'>http://schemas.xmlsoap.org/soap/envelope/</Namespace>
</Namespaces>
<Variable name='topLevelRequestElement' type='string'>
<XPath>local-name(/soap:Envelope/soap:Body/*[1])</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
Remember: the namespace prefix you use in the XPath expression need not match the namespace prefix used in the document. It's the namespace string that matters; the thing the prefix refers to. The following is equivalent to the above.
<ExtractVariables name='EV-SOAP-Operation'>
<Source>request</Source>
<VariablePrefix>soap</VariablePrefix>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<XMLPayload>
<Namespaces>
<Namespace prefix='s'>http://schemas.xmlsoap.org/soap/envelope/</Namespace>
</Namespaces>
<Variable name='topLevelRequestElement' type='string'>
<XPath>local-name(/s:Envelopr/s:Body/*[1])</XPath>
</Variable>
</XMLPayload>
</ExtractVariables>
It works fine! I became able to assign the entity name. Thanks!