0

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"');
axl g
  • 612
  • 2
  • 9
  • 20
  • Can't you change the xml to have at least a shortname for the namespace ie `xmlns:ns1="urn:www.someSite.com/myModel"` so you could do `/a/ns1:b/ns1:c` – A.B.Cade Apr 02 '12 at 13:39
  • no, I cannot change the xml, this is the format in which is saved in the database, and it cannot be changed. – axl g Apr 02 '12 at 13:46

1 Answers1

3

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'));
Community
  • 1
  • 1
A.B.Cade
  • 16,735
  • 1
  • 37
  • 53