delete a node from xml in oracle [message #474677] |
Wed, 08 September 2010 02:29 |
madhavi babburi
Messages: 117 Registered: May 2009 Location: Hyderabad
|
Senior Member |
|
|
Hi,
Need to delete a node from xml data having many nodes with same name. I have tried by using DELETEXML in the following way.
My test xml is...
with data as (
select XMLTYPE('<ROWSET>
<ROW>
<TABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>1 </VERS_MINOR>
</TABLE_T>
</ROW>
<ROW>
<POST_TABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>1 </VERS_MINOR>
</POST_TABLE_T>
</ROW>
</ROWSET>') val
from dual
)
select DELETEXML(val,'ROWSET/ROW/POST_TABLE_T') val
from data
The output is...
<ROWSET>
<ROW>
<TABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>1 </VERS_MINOR>
</TABLE_T>
</ROW>
[color=red][b]<ROW />[/b][/color]
</ROWSET>
I got an extra '<ROW />' node in the output. Shall i need to delete the extra part? If yes...how?
Or any alternative to delete a node from xml.
Regards,
Madhavi.
|
|
|
|
|
Re: delete a node from xml in oracle [message #474688 is a reply to message #474680] |
Wed, 08 September 2010 03:46 |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
You can use:
with data as (
select XMLTYPE('<ROWSET>
<ROW>
<TABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>1 </VERS_MINOR>
</TABLE_T>
</ROW>
<ROW>
<POST_TABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>1 </VERS_MINOR>
</POST_TABLE_T>
</ROW>
</ROWSET>') val
from dual
)
select DELETEXML(val,'ROWSET/ROW[POST_TABLE_T]')
from data
|
|
|
|