在Pl / Sql中ExtractValue Xml

时间:2016-07-20 15:32:14

标签: xml plsql extract-value

我尝试在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>

1 个答案:

答案 0 :(得分:0)

类似这样的事情

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;