如何在PL / SQL中读取Result头XML标记

时间:2016-10-14 13:54:59

标签: xml plsql

肥皂反应:

s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
  <GetResponse xmlns="http://temp.org/">
     <GetResult xmlns:a="http://schemas.datacontract.org/2004/07/ST" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:ResultHeader xmlns:b="http://schemas.datacontract.org/2004/07/CRM">
           <b:ResultCode>0000</b:ResultCode>
           <b:ResultDescription>Successful</b:ResultDescription>

           <b:TranscationID>?</b:TranscationID>
        </a:ResultHeader>

请建议我如何通过pl / SQL在响应xml中读取结果代码和结果描述,如果结果代码为000,则根据结果代码,然后我将读取其他子节点值,否则代码是000然后它将向用户显示例外。

1 个答案:

答案 0 :(得分:0)

如果您的XML中只有一个ResultHeader节点,那么您可以通过这种方式检查ResultCode

   -- get ResultCode value     
   l_resultCode:=  l_xml.extract('/s:Envelope/s:Body/GetResponse/GetResult/a:ResultHeader/b:ResultCode/text()', 'xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/ xmlns:a="http://schemas.datacontract.org/2004/07/CRM" xmlns:b="http://schemas.datacontract.org/2004/07/CRM"').GetStringVal(); 

   -- check ResultCode
   IF l_resultCode = '000' THEN
       -- if OK then get value from child nodes  
   ELSE
       -- else raise exception
       l_resultDescription:= l_xml.extract('/s:Envelope/s:Body/GetResponse/GetResult/a:ResultHeader/b:ResultDescription/text()', 'xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/ xmlns:a="http://schemas.datacontract.org/2004/07/CRM" xmlns:b="http://schemas.datacontract.org/2004/07/CRM"').GetStringVal(); 
       raise_application_error(-20001, 'ResultCode='||l_resultCode||', ResultDescription='||l_resultDescription);
   END IF;