通过pl/sql在xml中解析标签时面临的问题 [英] Facing issue in parsing a tag in xml through pl/sql
本文介绍了通过pl/sql在xml中解析标签时面临的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种通过简单的extract()或extractvalue()命令获取标签值的方法,但是我无法做到这一点.
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>');
我需要标记ns0:TransatorWebServiceContent_out的值,即输出为某些文本"
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?
推荐答案
您需要在EXTRACT函数中指定名称空间.试试这个:
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
注意:我需要更改您提供的XML:
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>');
这篇关于通过pl/sql在xml中解析标签时面临的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文