Accessing XML element [message #352954] |
Fri, 10 October 2008 05:43 |
kanis
Messages: 61 Registered: November 2006
|
Member |
|
|
I have a xml like below
<A>
<b>
<c>
<col>val1<col>
<col>val2<col>
<col>val3<col>
</c>
<c>
<col>val7<col>
<col>val8<col>
</c>
</b>
<b>
<c>
<col>val10<col>
</c>
<c>
<col>val11<col>
<col>val12<col>
</c>
</b>
</A>
Can any one let me know what code in pl/sql need to write if I want to access only "val10" from the above xml.
thanks for the help
|
|
|
|
|
|
|
|
Re: Accessing XML element [message #353616 is a reply to message #353181] |
Tue, 14 October 2008 05:57 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
After fixing your data:
SQL> with
2 data as (
3 select
4 xmltype('<A>
5 <b>
6 <c>
7 <col>val1</col>
8 <col>val2</col>
9 <col>val3</col>
10 </c>
11 <c>
12 <col>val7</col>
13 <col>val8</col>
14 </c>
15 </b>
16 <b>
17 <c>
18 <col>val10</col>
19 </c>
20 <c>
21 <col>val11</col>
22 <col>val12</col>
23 </c>
24 </b>
25 </A>') x
26 from dual ),
27 b as (
28 select column_value b, rownum rn
29 from data, table(xmlsequence(extract(x,'/A/b')))
30 ),
31 c as (
32 select column_value c, rownum rn
33 from (select b from b where rn=2), table(xmlsequence(extract(b,'/b/c')))
34 )
35 select extractvalue(value(c),'/col') val
36 from (select c from c where rn=1), table(xmlsequence(extract(c, '/c/col'))) c
37 /
VAL
------------
val10
1 row selected.
Regards
Michel
[Updated on: Tue, 14 October 2008 05:57] Report message to a moderator
|
|
|