在Pl / Sql

时间:2018-07-13 11:02:48

标签: oracle

我尝试在pl / sql中解析此xml中的值。

我想成为现实

hasLoanResult值,使其为“ true”

你能帮我吗:(??p

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<hasLoanResponse xmlns="http://tempuri.org/">
<hasLoanResult xsi:type="xsd:boolean">true</hasLoanResult>
</hasLoanResponse>
</soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:1)

您可以使用XMLQuery

import numpy as np

m = np.array([4, 5, 6])
n = np.array([1, 2, 3])

这声明了select xmlquery('declare namespace soap="http://www.w3.org/2003/05/soap-envelope"; (: :) declare default element namespace "http://tempuri.org/"; (: :) soap:Envelope/soap:Body/hasLoanResponse/hasLoanResult/text()' passing <your_xml_document> returning content).getstringval() as result from dual; 和默认名称空间,因此它可以匹配路径的相关部分。然后提取所需节点的文本,并将其作为字符串返回。

因此,您的示例文档是在线提供的:

soap

如果在PL / SQL变量中包含XML,则基本上是同一件事:

select xmlquery('declare namespace soap="http://www.w3.org/2003/05/soap-envelope"; (: :)
    declare default element namespace "http://tempuri.org/"; (: :)
    soap:Envelope/soap:Body/hasLoanResponse/hasLoanResult/text()'
  passing xmltype('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<hasLoanResponse xmlns="http://tempuri.org/">
<hasLoanResult xsi:type="xsd:boolean">true</hasLoanResult>
</hasLoanResponse>
</soap:Body>
</soap:Envelope>')
  returning content).getstringval() as result
from dual;

RESULT    
----------
true

如果您的XML文档位于CLOB或varchar2变量中,则只需将其更改为:

set serveroutput on

declare
  l_xml xmltype := xmltype('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<hasLoanResponse xmlns="http://tempuri.org/">
<hasLoanResult xsi:type="xsd:boolean">true</hasLoanResult>
</hasLoanResponse>
</soap:Body>
</soap:Envelope>');

  l_result varchar2(5);
begin
  select xmlquery('declare namespace soap="http://www.w3.org/2003/05/soap-envelope"; (: :)
      declare default element namespace "http://tempuri.org/"; (: :)
      soap:Envelope/soap:Body/hasLoanResponse/hasLoanResult/text()'
    passing l_xml
    returning content).getstringval()
  into l_result
  from dual;

  dbms_output.put_line(l_result);
end;
/

true


PL/SQL procedure successfully completed.

使用您自己的变量名。