首页 > 解决方案 > 从 xmltype/soap oracle 中提取值

问题描述

我需要从字段中获取“ineedthis”值

REQUEST_INFO:
...

<s:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<X-dynaTrace xmlns="http://ns.dynatrace.com/wcf" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">FW3;-1003312095;1;-56375709;115092;0;975784079;78</X-dynaTrace>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<storeContract xmlns="xxx/integration">
<storeRequest>
<contract>
<contractSeries>ineedthis</contractSeries>

select extractvalue(XMLType(sap.REQUEST_INFO),'s/s/storeContract/storeRequest/contract/contractSeries')
from sap

无法获得价值

标签: sqloraclexmltypeextract-value

解决方案


您正在尝试提取路径

s/s/storeContract/storeRequest/contract/contractSeries

但是您的 SOAP 响应没有任何名为的节点s;它在命名空间 s中有名为 Envelope、Header 和 Body 的节点。所以你可能想要路径:

/s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries

它本身会LPX-00601: Invalid token出错,因为它不知道是什么s:。您可以为命名空间提供第三个参数:

select extractvalue(XMLType(sap.request_info),
  '/s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries',
  'xmlns="xxx/integration" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"'
  ) as contractseries
from sap;

或者懒惰的方法是使用通配符命名空间并仅识别您想要的最终节点:

select extractvalue(XMLType(sap.request_info),'//*:contractSeries') as contractseries
from sap;

但是extractvaue已弃用,因此最好使用 XMLQuery - 仍然很懒惰:

select XMLQuery('//*:contractSeries/text()'
  passing XMLType(sap.request_info)
  returning content) as contractseries
from sap;

或使用显式命名空间:

select XMLQuery('
    declare default element namespace "xxx/integration";
    declare namespace s="http://schemas.xmlsoap.org/soap/envelope/";
    /s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries/text()'
  passing XMLType(sap.request_info)
  returning content) as contractseries
from sap;

CONTRACTSERIES                
------------------------------
ineedthis

db<>小提琴


推荐阅读