Oracle UpdateXML() changes XML structure?

自古美人都是妖i 提交于 2019-12-04 14:22:39

I think you can avoid the problem by replacing empty text with a temporary value, updating all the other text, and then replacing the temporary value with a null.

I don't understand XPath, there's probably a much better way to do this, but this seems to work:

SELECT
    --#3: Replace the temporary value with null, this keeps the start and end tag
    UpdateXML(
        --#2: Replace everything but the temporary value
        UpdateXML(
            --#1: Replace empty text with a temporary value
            UpdateXML(xmlData, '/TEST/VALUE[not(text())]', '<VALUE>TEMPORARY VALUE</VALUE>')
        ,'/TEST/VALUE[text()!="TEMPORARY VALUE"]/text()', 'hello')
    ,'/TEST/VALUE[text()="TEMPORARY VALUE"]/text()', null) examle
FROM (SELECT XMLType('<TEST><VALUE>hi</VALUE><VALUE>hola</VALUE><VALUE></VALUE></TEST>') as xmlData FROM DUAL);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!