【问题标题】:Parse SOAP XML in Oracle with example使用示例在 Oracle 中解析 SOAP XML
【发布时间】:2015-12-03 02:13:05
【问题描述】:

以下是“外部”表中的典型 SOAP 请求。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<settleResponse xmlns="urn:ABC">
 <settleReturn xmlns="">
  <message>Missing first name</message>
  <errorCode>INVALID_ACC</errorCode>
  <customData>offendingTransactionID=12345678</customData>
  <divisionRequestID xsi:nil="true"/>
  <status>Failed</status>
 </settleReturn>
</settleResponse>
</soapenv:Body>
</soapenv:Envelope>

我需要检索参数 errorCode、status... 并将它们保存到数据库表中。我该怎么做?

【问题讨论】:

  • SOAP XML 上方位于“消息”列内,数据类型为“外部”表中的 CLOB。
  • @apc :请查看此请求。

标签: xml oracle soap


【解决方案1】:

你可以用XMLQUERY提取节点内容:

select xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/message/text()'
    passing XMLType(message)
    returning content) as message,
  xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/errorCode/text()'
    passing XMLType(message)
    returning content) as errorCode,
  xmlquery('declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
      declare namespace urn = "urn:ABC";
      /soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn/status/text()'
    passing XMLType(message)
    returning content) as status
from external;

MESSAGE              ERRORCODE            STATUS   
-------------------- -------------------- ----------
Missing first name   INVALID_ACC          Failed

或者更简单,特别是如果您有多个消息要处理,XMLTABLE

select x.*
from external ext
cross join xmltable(
  xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as  "soapenv",
    'urn:ABC' as "urn"),
  '/soapenv:Envelope/soapenv:Body/urn:settleResponse/settleReturn'
  passing XMLType(ext.message)
  columns message varchar2(20) path 'message',
    errorCode varchar2(20) path 'errorCode',
    status varchar2(10) path 'status'
) x;

MESSAGE              ERRORCODE            STATUS   
-------------------- -------------------- ----------
Missing first name   INVALID_ACC          Failed    

在这两种情况下,您都需要指定命名空间,并且语法不同。 Read more about using these functions.

您可以使用insert into some_table (x, y, z) select ... 将它们直接插入到另一个表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多