Having a XMLTYPE column in an Oracle table, I would like to update the values of some xml elements using UpdateXML method but I have troubles doing so because of a namespace which is applied on an xml element which is not parent. The xml structure of my elmenets looks something like:
<a>
<b xmlns="urn:www.someSite.com/myModel">
<c>my value</c>
</b>
</a>
and an update of the following form it does not work:
UPDATE myTable
SET myColumn = UpdateXML(myColumn, '/a/b/c','other value', 'xmlns="urn:www.someSite.com/myModel"');
Pretty much the same as this post but uglier...
UPDATE myTable
SET myColumn = updatexml(myColumn ,
'/a/*',
updatexml(extract(myColumn , '/a/*'),
'b/c/text()',
'my new value',
'xmlns=urn:www.someSite.com/myModel'));
EDIT: If you have more then one b
element in a
you'll have to change the whole text within a
and not for each child, so you can try:
UPDATE myTable
SET myColumn = updatexml(myColumn ,
'/a/text()',
updatexml(extract(myColumn , '/a/*'),
'b/c/text()',
'my new value',
'xmlns=urn:www.someSite.com/myModel'));