I'm working with a web service that returns the output below. I'm having a hard time building the XMLTYPE variable from the output. I get the following error when trying to output the CreateUserSessionFromInstanceResult
ORA-30625: method dispatch on NULL SELF argument is disallowed
procedure xmltest is
str_xml varchar2(32000);
v_xml XMLTYPE;
BEGIN
str_xml :='<?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>
<CreateUserSessionFromInstanceResponse xmlns="http://archer-tech.com/webservices/">
<CreateUserSessionFromInstanceResult>4FFABEE05C4910A31FEC75D5FEDCDFB5</CreateUserSessionFromInstanceResult>
</CreateUserSessionFromInstanceResponse>
</soap:Body>
</soap:Envelope>';
v_xml := XMLTYPE(str_xml);
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()').getstringval());
END;
The error is on this line
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()').getstringval());
You're getting an error because your XPath expression
//CreateUserSessionFromInstanceResult/text()
matches nothing, and so extract(...)
returns NULL
. Of course, you can't call getstringval()
on NULL
, hence the error you see.
The reason your XPath isn't matching is because of namespaces. The xmlns
attribute on the <CreateUserSessionFromInstanceResponse>
element sets the namespace of this element and of the <CreateUserSessionFromInstanceResult>
element it contains to be "http://archer-tech.com/webservices/"
. On the other hand, your XPath expression is searching for the element with the name CreateUserSessionFromInstanceResult
in the default namespace, ""
.
The fix is to add a third parameter to extract
that declares this namespace. You do this in the same way as it appears in the XML:
HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()',
'xmlns="http://archer-tech.com/webservices/"').getstringval());