如何仅从 xml 结果中提取错误消息 [英] How can I extract only the error message from xml result
问题描述
如何从标签 VertexApplicationException
和 User login failed.
中提取值从下面的 xml 结果?
在我的包内,我使用make request api"调用来获取从顶点计算的税值,有时我收到错误作为我的 api 调用的响应,现在我需要将响应存储在表中,但只有我需要错误消息例如:VertexApplicationException 和用户登录失败.来自下面给出的 xml 响应标记
<S:身体><nsf:错误 xmlns:nsf="http://schemas.xmlsoap.org/soap/envelope/"><faultcode>nsf:Client</faultcode><faultstring>用户登录失败.</faultstring><细节><ns:VertexException xmlns:ns="urn:vertexinc:oseries:exception:1:0"><ns:exceptionType>VertexApplicationException</ns:exceptionType><ns:rootCause>用户登录失败.</ns:rootCause></ns:VertexException></detail>`在此处输入代码`</nsf:故障></S:身体></S:信封>
你可以试试下面的查询:
select a.* from XMLTABLE (xmlnamespaces( 'http://schemas.xmlsoap.org/soap/envelope/' 为 "S",'http://schemas.xmlsoap.org/soap/envelope/' 为nsf",'urn:vertexinc:oseries:exception:1:0' 为 "ns"),'/S:Envelope/S:Body/nsf:Fault/detail/ns:VertexException'通过XMLTYPE('<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:身体><nsf:错误 xmlns:nsf="http://schemas.xmlsoap.org/soap/envelope/"><faultcode>nsf:Client</faultcode><faultstring>用户登录失败.</faultstring><细节><ns:VertexException xmlns:ns="urn:vertexinc:oseries:exception:1:0"><ns:exceptionType>VertexApplicationException</ns:exceptionType><ns:rootCause>用户登录失败.</ns:rootCause></ns:VertexException></detail>`在此处输入代码`</nsf:故障></S:身体></S:信封>')列ExceptionType varchar2(40) 路径 'ns:exceptionType', RootCause varchar2(40) 路径 'ns:rootCause') 作为一个;
输出
+----------------------------+--------------------+|异常类型 |根本原因 |+------------------------------------+--------------------+|顶点应用异常 |用户登录失败.|+------------------------------------+--------------------+
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
;
Output
+----------------------------+--------------------+
| EXCEPTIONTYPE | ROOTCAUSE |
+----------------------------+--------------------+
| VertexApplicationException | User login failed. |
+----------------------------+--------------------+
这篇关于如何仅从 xml 结果中提取错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!