Pl/Sql 中的提取值 Xml

ExtractValue Xml in Pl/Sql

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

我想获取 <tax:resultCode>1</tax:resultCode> 标签值,以便它的 '1'

你能帮帮我吗:(?

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
                 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
                 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <soap:Header>
             <wsa:Action>http://tempuri.org/GetSerialNoDealerIsValidResponse</wsa:Action> 
             <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
             <wsse:Security>
                 <wsu:Timestamp wsu:Id="Timestamp-d434622e-2bcd-4e80-a258-e5e503a964b1">
                     <wsu:Created>2016-07-20T17:08:58.379+03:00</wsu:Created> 
                 </wsu:Timestamp>
             </wsse:Security>
         </soap:Header>
     </soap:Header>
     <soap:Body xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
     xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <tax:checkInventoryResponse xmlns:tax="http://www.avea.com.tr/TAXIM_INVENTORY_OPERATIONS">
             <ave:ResponseHeader xmlns:ave="http://www.avea.com.tr/aveaCommonTypes">
                 <ave:Tid>stringstringstringstring</ave:Tid>
             </ave:ResponseHeader>
             <tax:ResponseBody>
                 <tax:response>
                     <tax:ResponseItem>
                         <tax:resultCode>1</tax:resultCode>
                         <tax:responseValue>0000</tax:responseValue><tax:logID>stringstringstringstring</tax:logID> 
                     </tax:ResponseItem>
                 </tax:response>
             </tax:ResponseBody>
         </tax:checkInventoryResponse>
     </soap:Body>
 </soapenv:Envelope>

像这样

with xml as (select xmltype('<here you xml from question>') x from dual)

select EXTRACTVALUE(xml.x,'//tax:resultCode','xmlns:tax="http://www.avea.com.tr/TAXIM_INVENTORY_OPERATIONS"')
 from xml

此处输出

EXTRACTVALUE(XML.X,'//TAX:RESULTCODE','XMLNS:TAX="HTTP://WWW.AVEA.COM.TR/TAXIM_I
--------------------------------------------------------------------------------
1                                                             

"//" 用于标识当前节点的所有后代。例如,PurchaseOrder//ShippingInstructions 匹配 PurchaseOrder 元素下的任何 ShippingInstructions 元素。 https://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb04cre.htm#g1038245

或者您可以这样做(此表达式会找到所有节点,甚至是绑定到您不感兴趣的命名空间的节点。)

with xml as (select xmltype('<here you xml from question>') x from dual)
select EXTRACTVALUE(xml.x,'//*[local-name()="resultCode"]') from xml

或者你可以从根元素开始:

    with xml as (select xmltype('<here you xml from question>') x from dual)

select 
       extract(soapbody.column_value,
      '/tax:checkInventoryResponse/tax:ResponseBody/tax:response/tax:ResponseItem/tax:resultCode/text()',
      'xmlns:tax="http://www.avea.com.tr/TAXIM_INVENTORY_OPERATIONS"').getNumberVal()
from xml,
     TABLE(XMLSequence(extract(xml.x, '/soapenv:Envelope/*','xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'))) soapenv,
     TABLE(XMLSequence(extract(soapenv.column_value, '/soap:Body/*','xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'))) soapbody

对于 pl/sql 语句,它必须看起来像:

declare
 l_value varchar2(1);
begin

with xml as (select xmltype('<here you xml from question>') x from dual)

select EXTRACTVALUE(xml.x,'//tax:resultCode','xmlns:tax="http://www.avea.com.tr/TAXIM_INVENTORY_OPERATIONS"')
into l_value
 from xml;

end;