无法使用 XMLQuery 从 SOAP Web 服务响应中获取值

Unable to get the value from SOAP Webservice Response using XMLQuery

我正在使用 Oracle 的 XML 查询数据库函数来读取 SOAP Web 服务响应,但是响应元素 "result" 在该元素旁边包含命名空间子句 (xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/")名称,因此 XML 查询无法读取元素的值。

这是我收到的 Web 服务响应正文,我正在尝试读取 "result"

<env:Body>
        <ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">
        <result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>
        </ns0:getFlowTaskInstanceStatusResponse>
</env:Body>

.
The following Select statement returns NULL


SELECT xmlcast(XMLQuery('//result' PASSING l_xmldata RETURNING CONTENT) as varchar2(900))
  into l_extract
  from dual;

如果我从 XML 响应中删除命名空间文本,XML 查询函数将 return "COMPLETED"!然而,这不是一个实际的解决方法。

BR 哈尼

您有两个选择(我添加了一个 "env" 命名空间以使 xml 有效):

在查询中包含命名空间:

WITH test AS
  (SELECT xmltype(' 
<env:Body xmlns:env="myenv">        
<ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">        
<result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>        
</ns0:getFlowTaskInstanceStatusResponse>
</env:Body>') AS data
  FROM dual
  )
SELECT CAST( extractValue(test.data, '//ns0:result','xmlns:env="myenv" xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/') AS VARCHAR2(900) )
FROM test

忽略命名空间

WITH test AS
  (SELECT xmltype(' 
<env:Body xmlns:env="myenv">        
<ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">        
<result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>        
</ns0:getFlowTaskInstanceStatusResponse>
</env:Body>') AS data
  FROM dual
  )
SELECT CAST( extractValue(test.data, '//*[local-name() = "result"]') AS VARCHAR2(900) )
FROM test