Extracting values from xml in Oracle PL/SQL

2020-04-20 09:12发布

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Body>
  <ShipmentTrackingResponse xmlns="http://ws.aramex.net/ShippingAPI/v1/">
   <Transaction xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Reference1>001</Reference1>
    <Reference2 i:nil="true"/>
    <Reference3 i:nil="true"/>
    <Reference4 i:nil="true"/>
    <Reference5 i:nil="true"/>
  </Transaction>
  <Notifications xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
  <HasErrors>false</HasErrors>
  <TrackingResults xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"         
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
  <NonExistingWaybills xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"  
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <a:string>XXXXXXXXXX</a:string>
  </NonExistingWaybills>
 </ShipmentTrackingResponse>
</s:Body>

I have used the following queries to extract values, but how do i extract the NonExistingWaybills?

 SELECT EXTRACTVALUE(l_resp_xml,
                    '//ShipmentTrackingResponse/Transaction/Reference1',
                    'xmlns="http://ws.aramex.net/ShippingAPI/v1/"') 
  INTO l_response_result 
   FROM dual;

  DBMS_OUTPUT.put_line ( 'Result> Reference1=' || l_response_result);

  SELECT EXTRACTVALUE(l_resp_xml,
                     '//ShipmentTrackingResponse/TrackingResults',
                     'xmlns="http://ws.aramex.net/ShippingAPI/v1/"') 
    INTO l_response_result 
    FROM dual;

  DBMS_OUTPUT.put_line ( 'Result> TrackingResults=' || l_response_result);

  SELECT EXTRACTVALUE(l_resp_xml,
                     '//ShipmentTrackingResponse/NonExistingWaybills',
                     'xmlns="http://ws.aramex.net/ShippingAPI/v1/"') 
    INTO l_response_result 
    FROM dual;

  DBMS_OUTPUT.put_line ( 'Result> NonExistingWaybills=' || l_response_result);

The last query gives no result...

2条回答
Melony?
2楼-- · 2020-04-20 09:32

It returned results...

SELECT EXTRACTVALUE(l_resp_xml
                  , '//ShipmentTrackingResponse/NonExistingWaybills/node()'
                  , 'xmlns="http://ws.aramex.net/ShippingAPI/v1/"') 
INTO l_response_result
FROM dual;
DBMS_OUTPUT.put_line ( 'Result> NonExistingWaybills=' || l_response_result);
查看更多
The star\"
3楼-- · 2020-04-20 09:58

This will return the same result, but without select. I guess this is what you were looking for:

l_response_result := l_resp_xml.extract(
    '//ShipmentTrackingResponse/NonExistingWaybills/node()'
).getstringval();
查看更多
登录 后发表回答