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を使用しました、そしてここにあなたがそれを行う方法があります*名前空間)。

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 に答える