我正在尝试解析以下SOAP响应:
<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>
为此,我运行一个PL / SQL函数:
l_value_xml := apex_web_service.parse_xml( p_xml => l_soap_response,
p_xpath => '/TestFunctionResult/text()',
p_ns => 'xmlns="http://tempuri.org/"'
);
它没有给我任何回应。我在xpath在线测试仪中尝试了xpath。也没有任何回应。我认为这是错误的名称空间,但我找不到错误。
最佳答案
(免责声明:我不熟悉pl / sql,只熟悉XPath)
名称空间URI是正确的,但是您的原始XPath表达式是:
p_xpath => '/TestFunctionResult/text()'
尝试查找SOAP响应中不存在的内容。它寻找一个类似于以下内容的XML文档:
<TestFunctionResult>Verarbeitet: test</TestFunctionResult>
其中
TestFunctionResult
元素是最外面的元素。在您的实际文档中,情况并非如此。使用
//
(descendant-or-self::
)轴:p_xpath => '//TestFunctionResult/text()'
或者,甚至更好地,按如下所示键入层次结构:
p_xpath => '/Envelope/Body/TestFunctionResponse/TestFunctionResult/text()'
另一个潜在的错误源可能是您在PL / SQL代码中声明了默认名称空间,但是该名称空间并未自动与路径表达式中的元素相关联。
在具有XPath功能的编程语言中,更常见的是注册或声明带有前缀的名称空间:
xmlns:soap="http://tempuri.org/"
然后在路径表达式中为属于该名称空间的所有元素添加前缀:
p_xpath => '//soap:TestFunctionResult/text()'