在我的一个过程中,我使用REST调用(在APEX中)解析远程存储的XML文件,并尝试找到包含特定术语的节点。
这是文件的简化示例结构。此示例中的搜索词为“cloud”:
<map id="12343">
<topic id="23498">
<title>Topic title</title>
<p id="24334"> some sample text with term 'cloud' </p>
<ul id = "34334">
<li id="38743">List item without the term </li>
<li id="38438">List item with term 'Cloud'</li>
</ul>
</topic>
<topic id="23498">
<title>Title for this topic</title>
<p id="24334"> some sample text with term 'cloud' </p>
<ul id = "34334">
<li id="38743">List item without the term </li>
<li id="38438">List item without term'</li>
</ul>
</topic>
<topic id="23498">
<title>Title for this topic with term 'CLOUD' in caps</title>
<p id="24334"> some sample text with term 'Cloud' </p>
<ul id = "34334">
<li id="38743">List item without the term </li>
<li id="38438">List item without term'</li>
</ul>
</topic>
</map>
这段代码的作用是解析该文件并找出包含词语“cloud”的节点ID,无论该节点中的文本在何处。
我正在使用existnode来查找,但是结果不正确:
declare
sourceXML clob;
begin
delete from result_table;
for f in (select file_id, files_path from my_table)
loop
/*Get the contents of the file in the sourceXML*/
sourceXML := APEX_WEB_SERVICE.MAKE_REST_REQUEST(
p_url => f.file_path,
p_http_method => 'GET');
if instr(sourceXML,'<?xml version') != 0 then /* verify if it's valid xml file */
for t in (select topic_id
FROM xmltable('//map/topic' passing XMLTYPE(sourceXML)
columns topic_id VARCHAR2(10) PATH './@id')
where XMLExists('//text()[ora:contains(.,"sales cloud")]' passing XMLTYPE(sourceXML)))
loop
insert into result_table (file,topic) values (f.file_id, t.topic_id);
end loop;
end if;
end loop;
end;
我无法弄清楚我的错误在哪里。