Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PL/SQl中的xml提取元素_Xml_Oracle_Plsql_Xml Parsing_Extract - Fatal编程技术网

从PL/SQl中的xml提取元素

从PL/SQl中的xml提取元素,xml,oracle,plsql,xml-parsing,extract,Xml,Oracle,Plsql,Xml Parsing,Extract,下面是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

下面是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>
最后是提取值:但没有用!请帮忙


如何使用XmlTable

您需要向下/到特定的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节点中的路径

你可以在网上阅读更多

编辑我使用了您在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;

谢谢你的帮助。我做了以下工作,效果很好!!它解决了

选择x.UPDATEDESCRIPTION,x.UpdateDateTime进入l_响应_消息,l_响应_结果 从…起 从双t中选择XMLType.createxmll_clob_响应xml, xmltable xmlnamespaces 'http://ws.aramex.net/ShippingAPI/v1/"作为e,, 'http://schemas.microsoft.com/2003/10/Serialization/Arrays"作为一个,, 'http://schemas.xmlsoap.org/soap/envelope/"至于,, 违约'http://ws.aramex.net/ShippingAPI/v1/' , 's:Envelope/s:Body/ShipmentTrackingResponse/TrackingResults/a:KeyValueOfstringArrayOfTrackingResultmFAkxlpY/a:Value/TrackingResult[1]' 传递t.xml 柱 UpdateDescription varchar2128路径“UpdateDescription”, UpdateDateTime varchar2128路径“UpdateDateTime” x; dbms_output.put_line'The UpdateDescription=>'|| l|u response_消息;
dbms|u output.put_line'The UpdateDateTime=>'|| l|u response_result

谢谢你的帮助,但是默认的名称空间呢,我的问题就在这里。你能举个例子吗?我做了如下操作:选择EXTRACTl_resp_xml,//s:Envelope/s:Body/node,l_NAMESPACE_SOAP从dual提取l_resp_xml;然后:从xmltablexmlnamespaces的http://ws.aramex.net/ShippingAPI/v1/“作为一名律师,”http://schemas.microsoft.com/2003/10/Serialization/Arrays"作为n,,“/ShipmentTrackingResponse/a:TrackingResults/n:KeyValueOfstringArrayOfTrackingResultmFAkxlpY/n:Value/n:TrackingResult[1]”传递l_resp xml列更新描述VARCHAR2128路径“n:UPDATEDESCRIPTION[1]”xx;DBMS|u OUTPUT.put_line'Result>updatedescription='|| l|u response_message;但不幸的是没有用!!上面说找不到数据!!很高兴能帮上忙如果我的帖子确实回答了你的问题,请把它标记为一个回答,以帮助以后会来这里的其他人
 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
                    ) ;
    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;