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"');
2
  • 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 Commented Apr 2, 2012 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. Commented Apr 2, 2012 at 13:46

1 Answer 1

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'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.