如何仅从xml结果中提取错误消息

如何从xml结果下面的标签VertexApplicationExceptionUser login failed.中提取值?

在我的包中,我使用“ make request api”调用来获取从顶点计算的税额,有时我在对api调用的响应中得到错误,现在我需要将响应存储在表中,但仅我需要错误消息,例如:VertexApplicationException和用户登录失败。来自下面给出的xml响应标签

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <nsf:Fault xmlns:nsf="http://schemas.xmlsoap.org/soap/envelope/">
         <faultcode>nsf:Client</faultcode>
         <faultstring>User login failed.</faultstring>
         <detail>
            <ns:VertexException xmlns:ns="urn:vertexinc:oseries:exception:1:0">
               <ns:exceptionType>VertexApplicationException</ns:exceptionType>
               <ns:rootCause>User login failed.</ns:rootCause>
            </ns:VertexException>
         </detail>`enter code here`
      </nsf:Fault>
   </S:Body>
</S:Envelope>
hermite1 回答:如何仅从xml结果中提取错误消息

这样可以使您无所适从,但是XML特定查询也可以完成

regexp_substr(your_string,'<ns:rootCause>([A-Z]*)(.*)')
,

您可以尝试以下查询:

select a.*  from XMLTABLE (  

  xmlnamespaces( 'http://schemas.xmlsoap.org/soap/envelope/'   as "S",'http://schemas.xmlsoap.org/soap/envelope/' as "nsf",'urn:vertexinc:oseries:exception:1:0' as "ns"),'  
  /S:Envelope/S:Body/nsf:Fault/detail/ns:VertexException
  '  

  PASSING  

  XMLTYPE(  
  '  
  <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <nsf:Fault xmlns:nsf="http://schemas.xmlsoap.org/soap/envelope/">
         <faultcode>nsf:Client</faultcode>
         <faultstring>User login failed.</faultstring>
         <detail>
            <ns:VertexException xmlns:ns="urn:vertexinc:oseries:exception:1:0">
               <ns:exceptionType>VertexApplicationException</ns:exceptionType>
               <ns:rootCause>User login failed.</ns:rootCause>
            </ns:VertexException>
         </detail>`enter code here`
      </nsf:Fault>
   </S:Body>
</S:Envelope>  
  ')  

  columns  
    ExceptionType varchar2(40) path 'ns:exceptionType',RootCause varchar2(40) path 'ns:rootCause'  
) AS A  
;  

Check DEMO Here

输出

+----------------------------+--------------------+
| EXCEPTIONTYPE              | ROOTCAUSE          |
+----------------------------+--------------------+
| VertexApplicationException | User login failed. |
+----------------------------+--------------------+
本文链接:https://www.f2er.com/2994321.html

大家都在问