【问题标题】:How can I extract only the error message from xml result如何仅从 xml 结果中提取错误消息
【发布时间】:2020-03-26 22:34:27
【问题描述】:

如何从下面的 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>

【问题讨论】:

  • 您确定这是一个 Oracle APEX 问题吗?这里的上下文是什么?
  • 是的,在我的包中,我使用 make request api 调用来获取从顶点计算的税值,有时我收到错误作为我的 api 调用的响应,现在我需要将响应存储在表中但是只有错误消息例如:VertexApplicationException 和用户登录失败。从上面给定的 xml 响应标签

标签: api oracle11g oracle-apex apex-code oracle-apex-5.1


【解决方案1】:

您可以尝试以下查询:

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

【讨论】:

    【解决方案2】:

    这会让你非常接近,但 XML 特定的查询也可以完成这项工作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多