在 Oracle 中解析 SOAP XML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2383707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:08:21  来源:igfitidea点击:

Parsing SOAP XML in Oracle

xmloraclesoapxpathnamespaces

提问by budsiya

I am new to Oracle and I am working on something that needs to parse a SOAP request and save the address to DB Tables. I am using the XML parser in Oracle (XMLType) with XPath but am struggling since I can't figure out the way to parse the SOAP request because it has multiple namespaces.

我是 Oracle 的新手,我正在做一些需要解析 SOAP 请求并将地址保存到 DB 表的工作。我在 XPath 中使用 Oracle (XMLType) 中的 XML 解析器,但我很挣扎,因为我无法找出解析 SOAP 请求的方法,因为它有多个命名空间。

Could anyone give me an example?

谁能给我举个例子?

Thanks in advance!!!

提前致谢!!!

edit

编辑

It would be a typical SOAP request similar to the one below.

这将是一个典型的 SOAP 请求,类似于下面的请求。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"        
                  xmlns:soap="http://soap.service.****.com"> 
  <soapenv:Header /> 
  <soapenv:Body> 
    <soap:UpdateElem> 
      <soap:request> 
        <soap:att1>123456789</soap:att1> 
        <soap:att2 xsi:nil="true" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />                       
        <soap:att3>L</soap:att3> 
        ..... 
      </soap:request> 
    </soap:UpdateElem>
  </soapenv:Body> 
</soapenv:Envelope>

I need to retrieve parameters att1, att2... and save them in to a DB table.

我需要检索参数 att1、att2... 并将它们保存到数据库表中。

回答by APC

With Oracle's XML implementation there may several ways to shred a particular cabbage. Here is a solution which uses XMLTable()to isolate the attributes.

使用 Oracle 的 XML 实现,可以有多种方法来切碎特定的卷心菜。这是一个XMLTable()用于隔离属性的解决方案。

I have put your SOAP message into a table with an XMLType column:

我已将您的 SOAP 消息放入带有 XMLType 列的表中:

SQL> set long 5000
SQL> select xt.xmlmsg
  2  from xt
  3  where id = 1
  4  /

XMLMSG
--------------------------------------------------------------------------------
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                                  xmlns:soap="http://soap.service.****.com">
  <soapenv:Header />
  <soapenv:Body>
    <soap:UpdateElem>
      <soap:request>
        <soap:att1>123456789</soap:att1>
        <soap:att2 xsi:nil="true"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
        <soap:att3>L</soap:att3>
        .....
      </soap:request>
    </soap:UpdateElem>
  </soapenv:Body>
</soapenv:Envelope>
SQL>

This SELECT uses XPath to extract the attributes as columns. Note the use of the XMLTable()XMLNAMESPACES clause to define the, er, namespaces.

此 SELECT 使用 XPath 将属性提取为列。请注意使用XMLTable()XMLNAMESPACES 子句来定义命名空间。

SQL> select
  2      atts.att1
  3      , atts.att2
  4      , atts.att3
  5  from xt
  6       , xmltable(
  7              xmlnamespaces(
  8                  'http://schemas.xmlsoap.org/soap/envelope/' as "soapenv"
  9                     , 'http://soap.service.****.com' as "soap"
 10                     , 'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
 11                          )
 12               , '/soapenv:Envelope/soapenv:Body/soap:UpdateElem/soap:request'
 13               passing xt.xmlmsg
 14               columns
 15                   att1 number path 'soap:att1'
 16                   , att2 varchar2(10) path 'soap:att2/@xsi:nil'
 17                   , att3 char(1) path 'soap:att3'
 18                   ) atts
 19  where xt.id = 1
 20  /

      ATT1 ATT2       A
---------- ---------- -
 123456789 true       L

SQL>