Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como analisar xml por xmltable ao usar namespace em xml (Oracle)


Com base esta resposta

Deve ser assim:
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;