extractvalue returns null [message #169015] |
Mon, 24 April 2006 13:14 |
asowmyan
Messages: 1 Registered: April 2006
|
Junior Member |
|
|
Hi
I dont get any result when I run this pl/sql. But when I remove the xmlns...from <analyzeaddressresponse> element I get the correct output. Can anybody tell me why I dont get any output with xmlns??????
DECLARE
x XMLTYPE := XMLTYPE('
<AnalyzeAddressResponse xmlns="http://somesite.com/Advance/Analyze">
<AnalyzeAddressResult>
<Layers>
<Layer>
<Fields>
<Field>
<Name>Place</Name>
<Value>North Central</Value>
</Field>
<Field>
<Name>INSPECTOR</Name>
<Value>Nicole</Value>
</Field>
<Field>
<Name>OFFICE_NUM</Name>
<Value>123-4567</Value>
</Field>
</Fields>
</Layer>
</Layers>
</AnalyzeAddressResult>
</AnalyzeAddressResponse>');
BEGIN
FOR i IN ( SELECT EXTRACTVALUE(VALUE(t), '/Field/Name') field_name,
EXTRACTVALUE(VALUE(t), '/Field/Value') field_value
FROM TABLE(XMLSEQUENCE(EXTRACT(x, '/AnalyzeAddressResponse/AnalyzeAddressResult/Layers/Layer/Fields/Field'))) t )
LOOP
dbms_output.put_line(i.field_name || i.field_value);
END LOOP;
END;
Thanks
|
|
|
Re: extractvalue returns null [message #181635 is a reply to message #169015] |
Mon, 10 July 2006 23:37 |
hobbes
Messages: 173 Registered: January 2006
|
Senior Member |
|
|
You need to mention namespaces as parameters in the EXTRACT and EXTRACTVALUE functions as well.
SQL> DECLARE
2 x XMLTYPE := XMLTYPE('
3 <AnalyzeAddressResponse xmlns="http://somesite.com/Advance/Analyze">
4 <AnalyzeAddressResult>
5 <Layers>
6 <Layer>
7 <Fields>
8 <Field>
9 <Name>Place</Name>
10 <Value>North Central</Value>
11 </Field>
12 <Field>
13 <Name>INSPECTOR</Name>
14 <Value>Nicole</Value>
15 </Field>
16 <Field>
17 <Name>OFFICE_NUM</Name>
18 <Value>123-4567</Value>
19 </Field>
20 </Fields>
21 </Layer>
22 </Layers>
23 </AnalyzeAddressResult>
24 </AnalyzeAddressResponse>');
25 BEGIN
26 FOR i IN ( SELECT EXTRACTVALUE(VALUE(t),
27 '/Field/Name', 'xmlns="http://somesite.com/Advance/Analyze"') field_name,
28 EXTRACTVALUE(VALUE(t),
29 '/Field/Value', 'xmlns="http://somesite.com/Advance/Analyze"') field_value
30 FROM TABLE(XMLSEQUENCE(EXTRACT(x,
31 '/AnalyzeAddressResponse/AnalyzeAddressResult/Layers/Layer/Fields/Field',
32 'xmlns="http://somesite.com/Advance/Analyze"'))) t )
33 LOOP
34 dbms_output.put_line(i.field_name || i.field_value);
35 END LOOP;
36
37 END;
38 /
PlaceNorth Central
INSPECTORNicole
OFFICE_NUM123-4567
PL/SQL procedure successfully completed.
|
|
|