问题
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>
回答1:
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. |
+----------------------------+--------------------+
回答2:
Thhis would get you darn close, but an XML specific query might also do the job
regexp_substr(your_string, '<ns:rootCause>([A-Z]*)(.*)')
来源:https://stackoverflow.com/questions/59136796/how-can-i-extract-only-the-error-message-from-xml-result