如何从xml结果中仅提取错误消息 [英] How can I extract only the error message from xml result

查看:75
本文介绍了如何从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>

解决方案

您可以尝试以下查询:

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  
;  

在此处检查演示

输出

+----------------------------+--------------------+
| EXCEPTIONTYPE              | ROOTCAUSE          |
+----------------------------+--------------------+
| VertexApplicationException | User login failed. |
+----------------------------+--------------------+

How can I extract the value from the label VertexApplicationException and User login failed. from below xml result?

Inside my package, i am using 'make request api' call to get tax value calculated from vertex, sometimes i am getting error as response for my api call, now i need to store the response in table but only i need the error message ex: VertexApplicationException and User login failed. from the belowgiven xml response tag

<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>

解决方案

You can try below query:

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

Output

+----------------------------+--------------------+
| EXCEPTIONTYPE              | ROOTCAUSE          |
+----------------------------+--------------------+
| VertexApplicationException | User login failed. |
+----------------------------+--------------------+

这篇关于如何从xml结果中仅提取错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆