ORACLE PL SQL从SOAP XML中提取值

时间:2018-03-09 21:33:12

标签: xml oracle plsql

我有一个oracle过程,它使用UTL_HTTP向SOAP服务发出请求

这是由dbms_output.put_line(responseText)证明的返回响应;

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateProductionTicketResponse xmlns="http://tempuri.org/">
<CreateProductionTicketResult>246300</CreateProductionTicketResult>
<err />
</CreateProductionTicketResponse>
</soap:Body>
</soap:Envelope>

然后我创建了一个XMLTYPE对象

responseXml := XMLTYPE(responseText);

并尝试提取CreateProductionTicketResult的值

TICKET_ID := responseXML.EXTRACT('/soap:Envelope/soap:Body/CreateProductionTicketResponse/CreateProductionTicketResult/text()', 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"').getnumberval();

此行抛出错误

ORA-30625: method dispatch on NULL SELF argument is disallowed
ORA-06512: at line 41
30625. 00000 -  "method dispatch on NULL SELF argument is disallowed"
*Cause:    A member method of a type is being invoked with a NULL SELF
           argument.
*Action:   Change the method invocation to pass in a valid self argument.

我猜我搞砸了EXTRACT语法,但我无法弄清楚出了什么问题。

1 个答案:

答案 0 :(得分:2)

问题是响应节点中的第二个未命名的命名空间(并由结果节点隐式继承)。你可以在第二个参数中给出一个虚拟名称来提取,并在XPath中使用它(只要URL匹配,名称就不必匹配原始文档):

TICKET_ID := responseXML.EXTRACT('/soap:Envelope/soap:Body/anon:CreateProductionTicketResponse/anon:CreateProductionTicketResult/text()',
               'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:anon="http://tempuri.org/"').getnumberval();