Exctractvalue от xmltype / мыльного оракула - PullRequest
0 голосов
/ 28 марта 2019

мне нужно получить значение "в самом деле" из поля

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

не могу получить значение

1 Ответ

0 голосов
/ 28 марта 2019

Вы пытаетесь извлечь путь

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 <> fiddle

...