我正在使用oracle apex和pl / sql解析远程服务器上的XML文件 . 我使用 APEX_WEB_SERVICE.MAKE_REST_REQUEST
将xml文件转换为clob变量,然后使用XPATH和XMLTable获取特定文本 .
这是我的一个示例XML文件(注意,原始文件非常复杂,这只是文件中内容的表示):
<article>
<index>
<term>term1</term>
<term>term2</term>
</index>
<ul>
<li>this is text with term1</li>
</ul>
<p>this is another text with term1</p>
<p>this is text with term2</p>
</article>
<article>
<index>
<term>term2</term>
<term>term3</term>
</index>
<ul>
<li>this is text with term2</li>
</ul>
<p>this is another text with term1</p>
<p>this is text with term2</p>
</article>
这是我试图用这个文件做的事情:
-
获取文本中包含'term1'的节点列表 .
-
获取包含'term1'的文本行
在这个例子中,我应该得到以下内容:
li: this is text with term1
p: this is another text with term1
等等 .
我能够进行一般文本搜索,但它返回文章下的所有内容,而不仅仅是所需的元素 . 对于这个例子,我会在结果中获得 ul
以及 li
,因为我只需要 li
和其中的文本 .
FOR r IN ( SELECT rownum rn, termtext
FROM xmltable('/article//*[contains(.,"term1")]' passing XMLTYPE(sourceXML)
columns termtext VARCHAR2(500) PATH '.')
)
LOOP
DBMS_OUTPUT.PUT_LINE('Row: '||r.rn);
DBMS_OUTPUT.PUT_LINE('Text: '||r.termtext);
END LOOP;
sourceXML
是包含xml文件的clob .
有人可以建议使用正确的xpath吗?