Facing issue in parsing a tag in xml through pl/sql

巧了我就是萌 提交于 2019-12-25 13:14:34

问题


I am looking to find a way to get a tag value through simple extract() or extractvalue() command, however I am unable to do so.

create table foo(
    xml_response XMLTYPE
 );

 insert into foo values('<?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP-     ENV="http://schemas.xmlsoap.org/soap/envelope/"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns0:CSXWEBSVResponse xmlns:ns0="http://tempuri.org/TransatorWebService">
  <ns0:TransatorWebServiceContent_out>Some     Text</ns0:TransatorWebServiceContent_out>
</ns0:CSXWEBSVResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>');

I need value of tag ns0:TransatorWebServiceContent_out, i.e. output is 'Some text'

 SELECT extract(xml_response,'SOAP-ENV:Envelope/SOAP-    ENV:Body/ns0:CSXWEBSVResponse/ns0:TransatorWebServiceContent_out/text()').getstringval() "REFERENCE" FROM foo

 ORA-31011: XML parsing failed
 ORA-19202: Error occurred in XML processing
 LPX-00601: Invalid token in: 'SOAP-ENV:Envelope/SOAP-    ENV:Body/ns0:CSXWEBSVResponse/ns0:TransatorWebServiceContent_Waout/text()'

I went through similar question/answers but non of them could help me fully. What am I missing here?


回答1:


You need to specify the namespace in the EXTRACT function. Try this:

SELECT EXTRACT(xml_response,'//ns0:TransatorWebServiceContent_out/text()','xmlns:ns0="http://tempuri.org/TransatorWebService"').getStringVal() 
FROM foo

NOTE: I needed to change a little bit the XML you provided:

CREATE TABLE foo(
  xml_response XMLTYPE
);

INSERT INTO foo VALUES('<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns0:CSXWEBSVResponse xmlns:ns0="http://tempuri.org/TransatorWebService">
  <ns0:TransatorWebServiceContent_out>Some     Text</ns0:TransatorWebServiceContent_out>
</ns0:CSXWEBSVResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>');


来源:https://stackoverflow.com/questions/31812807/facing-issue-in-parsing-a-tag-in-xml-through-pl-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!