在xml(Oracle)中使用命名空间时如何通过xmltable解析xml
发布时间:2020-12-16 23:00:50 所属栏目:百科 来源:网络整理
导读:I want to parse a xml string that is a web service response sent from servier,the xml looks like this: ?xml version="1.0" encoding="utf-8"?soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/20
<?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> 我想在元素addResult之间获得值20.我的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;
解决方法
基于
this answer
应该是这样的: 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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |