开发者

Get value from SOAP Message using Xpath

开发者 https://www.devze.com 2023-02-18 04:24 出处:网络
I\'m trying to get a value fromfrom the following SOAP Message, but maybe my syntax on XPath is not good

I'm trying to get a value from from the following SOAP Message, but maybe my syntax on XPath is not good

XPath I'm using:

/soap:Body/n0:RequestSystemGuidResponse/SystemGuid

Error:

Error processing xml. Namespace prefix 'n0' is not defin开发者_高级运维ed.

SOAP XML:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header></soap-env:Header>
    <soap-env:Body>
        <n0:RequestSystemGuidResponse 
            xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
            <Errors></Errors>
            <SystemGuid>E050831C9CA1D1F1A9FC005056B95649</SystemGuid>
        </n0:RequestSystemGuidResponse>
    </soap-env:Body>
</soap-env:Envelope>


You haven't declared the namespace prefix 'n0' to the environment that's evaluating your XPath expression. Namespace declarations used in XPath need to be declared in the environment in which XPath is used.

If you need help on how to do that, tell us how you're using XPath. Are you passing "/soap:Body/n0:RequestSystemGuidResponse/SystemGuid" to a particular method on a particular class? in what library? what language? You need to tell it that the "n0" prefix stands for the namespace whose URI is "urn:sap-com:document:sap:soap:functions:mc-style".

Apparently you've already declared the namespace prefix "soap", or else you would be getting an error about that too.

Also, once you get that fixed, your XPath expression will need to be modified, because right now it will only work if is the top-level element in your input XML. Instead of

/soap:Body/n0:RequestSystemGuidResponse/SystemGuid

you need

/*/soap:Body/n0:RequestSystemGuidResponse/SystemGuid

(assuming that the soap prefix is declared for the namespace whose URI is "http://schemas.xmlsoap.org/soap/envelope/").

0

精彩评论

暂无评论...
验证码 换一张
取 消