2

下面是 SOAP 服务的响应。我如何在 Pl/SQL 中提取值。我列出了一些我尝试过的方法

<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">
     <a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY>
      <a:Key>4738079651</a:Key>
      <a:Value>
      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH247</UpdateCode>
       <UpdateDescription>Supporting Document Returned to Shipper</UpdateDescription>
       <UpdateDateTime>2013-07-15T19:29:00</UpdateDateTime> 
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH369</UpdateCode>
       <UpdateDescription>SMS Sent to Consignee</UpdateDescription>
       <UpdateDateTime>2013-07-12T09:10:00</UpdateDateTime>   
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH033</UpdateCode>
       <UpdateDescription>Attempted Delivery - Payment Declined by Customer</UpdateDescription>
       <UpdateDateTime>2013-07-11T17:20:00</UpdateDateTime>
       <UpdateLocation>Goa Branch-GOI,India</UpdateLocation>
       <Comments/>
       <ProblemCode>A18</ProblemCode>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH369</UpdateCode>
       <UpdateDescription>SMS Sent to Consignee</UpdateDescription>
       <UpdateDateTime>2013-07-11T10:36:00</UpdateDateTime>
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH003</UpdateCode>
       <UpdateDescription>Out for Delivery</UpdateDescription>
       <UpdateDateTime>2013-07-11T10:19:00</UpdateDateTime>
       <UpdateLocation>Goa Branch-GOI,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH203</UpdateCode>
       <UpdateDescription>Record Created</UpdateDescription>
       <UpdateDateTime>2013-07-05T00:39:00</UpdateDateTime>
       <UpdateLocation>Nehru Place Branch,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>
    </a:Value>
   </a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY>
  </TrackingResults>
<NonExistingWaybills xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></ShipmentTrackingResponse></s:Body>
</s: Envelope>

我如何提取价值,我真的被卡住了,已经尝试了所有方法。一些方法如下:

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

最后用于提取值:但没用!请帮忙!!

SELECT EXTRACTVALUE(l_resp_xml, 
'//TrackingResults/a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY/a:Value/TrackingResult[1]/UpdateDescription', 'xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"')INTO l_response_result FROM dual;
DBMS_OUTPUT.put_line ( 'Result> l_response_clobExtract=' || l_response_result);

如何使用 XmlTable?

4

2 回答 2

2

您需要向下/到特定的 XML 标记/节点

 SELECT *
   FROM XMLTable('$dat//xmlpath' --the path to the node you want to start reading from
                   PASSING your_xml_node AS "dat"
                   COLUMNS
                       vcol NUMBER PATH 'col_path', --from your given node
                       ...etc
                    ) ;

对于您要读取的每个 XML 值,您需要在下面添加一列COLUMNS并将其映射到给定 XML 节点中的路径

您可以在Oracle Docs中阅读更多内容



编辑我使用了你在你的 OP 中列出的 XML,这是你可以做到的(我没有访问你的http://ws.aramex.net/ShippingAPI/v1/架构所以我使用 a*来查询任何架构/命名空间)。

处理XML时最重要的是路径,您没有得到任何结果的原因是因为您在路径的某个地方出现了问题。我花了一段时间才学会这个,祝你好运:)

    SELECT *
      FROM XMLTABLE (
              xmlnamespaces (
                 'http://schemas.xmlsoap.org/soap/envelope/' AS "s",
                 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' AS "a"),
              '$xd/s:Envelope/s:Body/*:ShipmentTrackingResponse/*:TrackingResults/a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY'
              PASSING xmltype (
                         '<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">
     <a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY>
      <a:Key>4738079651</a:Key>
      <a:Value>
      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH247</UpdateCode>
       <UpdateDescription>Supporting Document Returned to Shipper</UpdateDescription>
       <UpdateDateTime>2013-07-15T19:29:00</UpdateDateTime> 
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH369</UpdateCode>
       <UpdateDescription>SMS Sent to Consignee</UpdateDescription>
       <UpdateDateTime>2013-07-12T09:10:00</UpdateDateTime>   
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH033</UpdateCode>
       <UpdateDescription>Attempted Delivery - Payment Declined by Customer</UpdateDescription>
       <UpdateDateTime>2013-07-11T17:20:00</UpdateDateTime>
       <UpdateLocation>Goa Branch-GOI,India</UpdateLocation>
       <Comments/>
       <ProblemCode>A18</ProblemCode>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH369</UpdateCode>
       <UpdateDescription>SMS Sent to Consignee</UpdateDescription>
       <UpdateDateTime>2013-07-11T10:36:00</UpdateDateTime>
       <UpdateLocation>Mumbai,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH003</UpdateCode>
       <UpdateDescription>Out for Delivery</UpdateDescription>
       <UpdateDateTime>2013-07-11T10:19:00</UpdateDateTime>
       <UpdateLocation>Goa Branch-GOI,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>

      <TrackingResult>
       <WaybillNumber>4738079651</WaybillNumber>
       <UpdateCode>SH203</UpdateCode>
       <UpdateDescription>Record Created</UpdateDescription>
       <UpdateDateTime>2013-07-05T00:39:00</UpdateDateTime>
       <UpdateLocation>Nehru Place Branch,India</UpdateLocation>
       <Comments/>
       <ProblemCode/>
      </TrackingResult>
    </a:Value>
   </a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY>
  </TrackingResults>
<NonExistingWaybills xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></ShipmentTrackingResponse></s:Body>
</s:Envelope>') AS "xd"
              COLUMNS key_col NUMBER PATH 'a:Key',
                      values_col XMLTYPE PATH 'a:Value') xx;
于 2013-07-30T15:36:16.850 回答
0

感谢贾法尔的帮助。我做了以下工作,效果很好!!解决了…………

select x.UPDATEDESCRIPTION , x.UpdateDateTime into l_response_message, l_response_result from (select XMLType.createxml(l_clob_response) xml from dual) t, xmltable( xmlnamespaces ( 'http://ws.aramex.net/ShippingAPI/v1/' as "e", 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' as "a", 'http://schemas.xmlsoap.org/soap/envelope/' as "s", default 'http://ws.aramex.net/ShippingAPI/v1/' ), 's:Envelope/s:Body/ShipmentTrackingResponse/TrackingResults/a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY/a:Value/TrackingResult[1]' passing t.xml columns UpdateDescription varchar2(128) path 'UpdateDescription', UpdateDateTime varchar2(128) path 'UpdateDateTime' ) x; dbms_output.put_line('The UpdateDescription =>' || l_response_message); dbms_output.put_line('The UpdateDateTime =>' || l_response_result);

于 2013-08-01T12:57:06.920 回答