In one of my procedure I am parsing a remote stored XML file using a REST call (in APEX) and trying to find out nodes that contain specific terms.
Here's a simplified example structure of the file. The search term in this example is '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>
The code is expected to parse this file and find out IDs of the node that contains the term 'cloud' anywhere in the text inside that node.
I am using existnode to find this out, but I am not getting correct results:
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;
I am not able to figure out where I am going wrong.