XML Oracle:从多个重复的子节点中提取特定属性 [英] XML Oracle: Extract specific attribute from multiple repeating child nodes
问题描述
我无法理解我看到的其他问题,因为它们有些不同.
I'm having trouble understanding other questions I see, as they are a little bit different.
我从Web服务vi UTL_HTTP获取XML作为响应. XML具有重复的子节点,我只想提取1个特定值.
I'm getting a XML as response from a webservice vi UTL_HTTP. The XML has repeating child nodes and I want to extract only 1 specific value.
响应XML:
<Customer>
<Loyalty>
<Client>
<Identifications>
<Identification>
<Form>Form1</Form>
<value>1234</value>
</Identification>
<Identification>
<Form>Form2</Form>
<value>4442</value>
</Identification>
<Identification>
<Form>Form3</Form>
<value>9995</value>
</Identification>
</Identifications>
</Client>
</Loyalty>
</Customer>
仅在节点<Form>
="Form3"的情况下,才需要提取节点<value>
.
I need to extract the the node <value>
only where the node <Form>
= "Form3".
因此,在我的代码中,我收到了另一个函数的响应
So, within my code, I receive the response from another function
v_ds_xml_response XMLTYPE;
-- Here would lie the rest of the code (omitted) preparing the XML and next calling the function with it:
V_DS_XML_RESPONSE := FUNCTION_CALL_WEBSERVICE(
P_URL => V_DS_URL, --endpoint
P_DS_XML => V_DS_XML, --the request XML
P_ERROR => P_ERROR);
这样,我创建了一个LOOP来存储值.我尝试使用WHERE甚至创建一个类型(下面的V_IDENTIFICATION是该类型),但是它没有返回任何内容(空).
With that, I created a LOOP to store the values. I've tried using WHERE and even creating a type (V_IDENTIFICATION below is the type), but It didn't return anything (null).
for r IN (
SELECT
ExtractValue(Value(p),'/Customer/Loyalty/Client/Identifications/Identification/*[local-name()="Form"]/text()') as form,
ExtractValue(Value(p),'/Customer/Loyalty/Client/Identifications/Identification/*[local-name()="value"]/text()') as value
FROM TABLE(XMLSequence(Extract(V_DS_XML_RESPONSE,'//*[local-name()="Customer"]'))) p
LOOP
V_IDENTIFICATION.FORM := r.form;
V_IDENTIFICATION.VALUE := r.value;
END LOOP;
SELECT
V_IDENTIFICATION.VALUE
INTO
P_LOYALTY_VALUE
FROM dual
WHERE V_IDENTIFICATION.TIPO = 'Form3';
注意,P_LOYALTY_VALUE是我的过程中的OUT参数
Note, P_LOYALTY_VALUE is an OUT parameter from my Procedure
推荐答案
Aaand我设法找到了解决方案,这很简单,只需添加[text()="Form3"]/.../来确定Xpath如
Aaand I managed to find the solution, which is quite simple, just added [text()="Form3"]/.../" to predicate the Xpath as in
SELECT
ExtractValue(Value(p),'/Customer/Loyalty/Client/Identifications/Identification/*[local-name()="Form"][text()="Form3"]/text()') as form,
ExtractValue(Value(p),'/Customer/Loyalty/Client/Identifications/Identification/Form[text()="Form3"]/.../*[local-name()="value"]/text()') as value
还提取了这些值,只是将它们直接发送到过程的OUT参数中:
Also extracted the values just sending them directly into the procedure's OUT parameter:
P_FORM := r.form;
P_LOYALTY_VALUE := r.value;
这篇关于XML Oracle:从多个重复的子节点中提取特定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!