【问题标题】:PL/SQL XMLTYPE ORA-30625PL/SQL XMLTYPE ORA-30625
【发布时间】:2014-04-24 17:45:50
【问题描述】:

我正在使用返回以下输出的 Web 服务。我很难从输出中构建 XMLTYPE 变量。尝试输出 CreateUserSessionFromInstanceResult 时出现以下错误

ORA-30625: 不允许对 NULL SELF 参数进行方法调度

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;

【问题讨论】:

    标签: oracle plsql xmltype


    【解决方案1】:

    错误就在这一行

    HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()').getstringval());
    

    您收到错误是因为您的 XPath 表达式

    //CreateUserSessionFromInstanceResult/text()
    

    什么都不匹配,所以extract(...) 返回NULL。当然,您不能在NULL 上调用getstringval(),因此您会看到错误。

    您的 XPath 不匹配的原因是名称空间。 &lt;CreateUserSessionFromInstanceResponse&gt; 元素上的 xmlns 属性将该元素及其包含的 &lt;CreateUserSessionFromInstanceResult&gt; 元素的命名空间设置为 "http://archer-tech.com/webservices/"。另一方面,您的 XPath 表达式正在默认命名空间 "" 中搜索名称为 CreateUserSessionFromInstanceResult 的元素。

    解决方法是向声明此命名空间的extract 添加第三个参数。执行此操作的方式与它在 XML 中显示的方式相同:

    HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()',
                        'xmlns="http://archer-tech.com/webservices/"').getstringval());
    

    【讨论】:

      【解决方案2】:

      我遇到了类似的情况,添加额外的参数对我不起作用。

      对我来说,解决方案是在使用 getstringval 之前检查节点是否存在并进行空值检查,如下所示:

      if v_xml.existsnode('//CreateUserSessionFromInstanceResult', 'xmlns="http://archer-tech.com/webservices/"') > 0 and v_xml.extract('//CreateUserSessionFromInstanceResult/text()', 'xmlns="http://archer-tech.com/webservices/"') is not null then
      HTP.P(v_xml.extract('//CreateUserSessionFromInstanceResult/text()', 'xmlns="http://archer-tech.com/webservices/"').getstringval());
      end if;
      
      只做空检查可能就足够了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多