【问题标题】:exctractvalue from xmltype / soap oracle从 xmltype/soap oracle 中提取值
【发布时间】:2019-08-19 00:22:35
【问题描述】:

我需要从字段中获取“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

无法获得价值

【问题讨论】:

  • 在不了解 XML 的完整结构的情况下,很难确定 extractValue 的正确路径。能否请您发布一个完整的[简化] XML?

标签: sql oracle xmltype extract-value


【解决方案1】:

您正在尝试提取路径

s/s/storeContract/storeRequest/contract/contractSeries

但是您的 SOAP 响应没有任何名为 s 的节点;它在 namespace 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<>fiddle

【讨论】:

    猜你喜欢
    • 2013-07-06
    • 1970-01-01
    • 2020-02-08
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    相关资源
    最近更新 更多