如何使用PL / SQL提取wsse BinarySecurityToken

时间:2016-07-25 17:51:00

标签: xml oracle soap plsql

如何使用PL / SQL从以下SOAP有效内容中提取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 个答案:

答案 0 :(得分:1)

你不需要PL / SQL;您可以在纯SQL中使用XQuery:

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