2015-09-07 100 views
0

下面是表'external'中的典型SOAP请求。用示例解析SOAP中的SOAP XML

<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 ...并将它们保存到数据库表中。我怎样才能做到这一点?更简单地说

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

+0

上面的SOAP XML是在'message'列中,数据类型是'external'表中的CLOB。 –

+0

@apc:请查看此请求。 –

回答

0

您可以用XMLQUERY提取节点内容

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 ...中插入其他表格。