2016-07-25 27 views
0

如何使用PL/SQL從以下SOAP負載中提取BinarySecurityToken?如何使用PL/SQL提取wsse BinarySecurityToken

<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"> 
    <wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken> 
</wsse:Security> 

我希望提取 「expectedToken」 作爲結果

感謝

回答

1

你不neex PL/SQL;你可以使用一個XQuery在普通的SQL:

select XMLQuery('declare namespace wsse = "http://schemas.xmlsoap.org/ws/2002/12/secext"; (::) 
    /wsse:Security/wsse:BinarySecurityToken/text()' 
    passing XMLType('<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"> 
    <wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken> 
</wsse:Security>') 
    returning content) 
from dual; 

XMLQUERY('DECLARENAMESPACEWSSE="HTTP://SCHEMAS.XMLSOAP.ORG/WS/2002/12/SECEXT";(: 
-------------------------------------------------------------------------------- 
expectedToken 

如果您已經獲得在PL/SQL響應,並希望繼續使用它,那麼如果SOAP值是一個字符串變量,你可以這樣做:

set serveroutput on 
declare 
    soap varchar2(500); 
    token varchar2(200); 
begin 
    soap := '<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"> 
    <wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken> 
</wsse:Security>'; 

    select XMLQuery('declare namespace wsse = "http://schemas.xmlsoap.org/ws/2002/12/secext"; (::) 
    /wsse:Security/wsse:BinarySecurityToken/text()' 
    passing XMLType(soap) 
    returning content).getStringVal() 
    into token 
    from dual; 

    dbms_output.put_line(token); 
end; 
/

PL/SQL procedure successfully completed. 

expectedToken 
+0

嘿亞歷克斯,非常感謝你!問候 –