【问题标题】:Oracle 12c XML get value from responseOracle 12c XML 从响应中获取值
【发布时间】:2021-08-10 19:08:12
【问题描述】:

我是 PL/SQL 的新手,我需要使用肥皂网络服务。我无法从此响应中提取 p-address 值:

response xml:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getAddressForIpResponse xmlns="urn:USR1">
      <p-address xsi:type="xsd:string">11.11.11.11:2222</p-address>
    </getAddressForIpResponse>
  </soap:Body>
</soap:Envelope>

我尝试了 EXTRACTVALUE 的各种组合,但没有成功。任何帮助表示赞赏!

【问题讨论】:

    标签: xml oracle soap plsql


    【解决方案1】:

    可以extractvalue做到这一点:

    select extractvalue(
      xmltype(response_string), 
      '/soap:Envelope/soap:Body/getAddressForIpResponse/p-address',
      'xmlns="urn:USR1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"')
    from dual;
    

    但是extractvaluedeprecated;所以你应该使用XMLQuery:

    select XMLQuery(
      'declare default element namespace "urn:USR1";
       declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
       /soap:Envelope/soap:Body/getAddressForIpResponse/p-address/text()'
      passing xmltype(response_string)
      returning content).getStringval()
    from dual;
    

    无论哪种方式,您都需要提供默认命名空间和soap 命名空间。

    db<>fiddle

    如果要提取多位数据,也可以使用 XMLTable;在这里它不会增加太多,但它会是这样的:

    select ip_address
    from XMLTable (
      XMLNamespaces (
        default 'urn:USR1',
        'http://schemas.xmlsoap.org/soap/envelope/' as "soap"
      ),
      '/soap:Envelope/soap:Body/getAddressForIpResponse/p-address'
      passing xmltype(response_string)
      columns ip_address varchar2(15) path '.');
    

    db<>fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      相关资源
      最近更新 更多