Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在xml(Oracle)中使用名称空间时如何通过xmltable解析xml_Xml_Oracle_Plsql - Fatal编程技术网

在xml(Oracle)中使用名称空间时如何通过xmltable解析xml

在xml(Oracle)中使用名称空间时如何通过xmltable解析xml,xml,oracle,plsql,Xml,Oracle,Plsql,我想解析一个xml字符串,它是servier发送的web服务响应,xml如下所示: declare v_xml clob; begin v_xml := '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/200

我想解析一个xml字符串,它是servier发送的web服务响应,xml如下所示:

declare    
  v_xml clob;    
begin    
  v_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>    
      <addResponse xmlns="http://tempuri.org/">    
        <addResult>20</addResult>    
      </addResponse>    
    </soap:Body>    
  </soap:Envelope>';    
  for c in (select results    
              from xmltable(xmlnamespaces(default 'http://tempuri.org/',    
                                          'http://schemas.xmlsoap.org/soap/envelope/' as    
                                          "soap" ),    
                            'soap:Envelope/soap:Body/addResponse' passing    
                            xmltype(v_xml) columns results varchar(100) path    
                            './addResult')) loop    
    dbms_output.put_line('the result of calculation is : ' || c.results);    
  end loop;    
end;
我想得到元素之间的值20 addResult。我的plsql代码段如下所示:

declare
  v_xml clob;
begin
  v_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>
      <addResponse xmlns="http://tempuri.org/">
        <addResult>20</addResult>
      </addResponse>
    </soap:Body>
  </soap:Envelope>';
  for c in (select results 
        from xmltable('Envelope/Body/addResponse' passing xmltype(v_xml) 
        columns results varchar(100) path './addResult')
       )
  loop
    dbms_output.put_line('the result of calculation is : ' || c.results);
  end loop;
end;
似乎没有打印出任何内容,但是如果我删除名称空间“soap”,代码运行良好,那么有人能告诉我,当xml有名称空间时,如何获得值20吗

基于

应该是这样的:

declare    
  v_xml clob;    
begin    
  v_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>    
      <addResponse xmlns="http://tempuri.org/">    
        <addResult>20</addResult>    
      </addResponse>    
    </soap:Body>    
  </soap:Envelope>';    
  for c in (select results    
              from xmltable(xmlnamespaces(default 'http://tempuri.org/',    
                                          'http://schemas.xmlsoap.org/soap/envelope/' as    
                                          "soap" ),    
                            'soap:Envelope/soap:Body/addResponse' passing    
                            xmltype(v_xml) columns results varchar(100) path    
                            './addResult')) loop    
    dbms_output.put_line('the result of calculation is : ' || c.results);    
  end loop;    
end;