Reputation: 145
I am trying to parse the following SOAP response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TestFunctionResponse xmlns="http://tempuri.org/">
<TestFunctionResult>Verarbeitet: test</TestFunctionResult>
</TestFunctionResponse>
</s:Body>
</s:Envelope>
To do this I run an PL/SQL function:
l_value_xml := apex_web_service.parse_xml( p_xml => l_soap_response,
p_xpath => '/TestFunctionResult/text()',
p_ns => 'xmlns="http://tempuri.org/"'
);
It gives me no response. I tried the xpath in an xpath online tester. There is also no response. I think it is a wrong namespace but I could not find the error.
Upvotes: 2
Views: 1302
Reputation: 22617
(Disclaimer: I am not familiar with pl/sql, only with XPath)
The namespace URI is correct, but your original XPath expression:
p_xpath => '/TestFunctionResult/text()'
tries to find something which is not present in the SOAP response. It looks for an XML document that looks similar to:
<TestFunctionResult>Verarbeitet: test</TestFunctionResult>
where the TestFunctionResult
element is the outermost element. In your actual document, that's not the case.
Use the //
(descendant-or-self::
) axis:
p_xpath => '//TestFunctionResult/text()'
Or, even better, type out the hierarchy like this:
p_xpath => '/Envelope/Body/TestFunctionResponse/TestFunctionResult/text()'
Another potential source of error could be that you declare a default namespace in the PL/SQL code, but that this namespace is not automatically associated with the elements in the path expression.
In programming languages that have XPath functionality, it is much more common to register or declare a namespace with a prefix:
xmlns:soap="http://tempuri.org/"
And then prefix all elements belonging to that namespace in path expressions:
p_xpath => '//soap:TestFunctionResult/text()'
Upvotes: 3