有名称空间时的UPDATEXML

问题描述 投票:1回答:1

我必须更新XML的值:

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
                  xmlns:o="urn:schemas-microsoft-com:office:office" 
                  xmlns:x="urn:schemas-microsoft-com:office:excel" 
                  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
                  xmlns:html="http://www.w3.org/TR/REC-html40">
            <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
                <Author>XXXXXX</Author>
                <LastAuthor>UCB User</LastAuthor>
                <Created>2019-10-31T13:04:09Z</Created>
                <Version>14.00</Version>
            </DocumentProperties>
            <a>5</a>
        </Workbook>

在我的情况下,该XML在表tt字段xml_val中。

目标XPath为/ Workbook / DocumentProperties / Created,其值为2019-10-31T13:04:09Z,必须替换为2020-01-08

我绑定了此代码:

select UPDATEXML(xml_val,
   '/Workbook/DocumentProperties/Created/text()','2020-01-08',
    'xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
              xmlns:o="urn:schemas-microsoft-com:office:office" 
              xmlns:x="urn:schemas-microsoft-com:office:excel" 
              xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
              xmlns:html="http://www.w3.org/TR/REC-html40"').getClobVal() as last
from tt;

//。getClobVal()最后是因为ORA-21500:内部错误代码,参数:[%s],[%s],[%s],[%s],[%s], [%s],[%s],[%s]([here

上面的代码没有任何改变。我觉得这是因为在[[DocumentProperties标记中声明了另一个名称空间。但是我不知道如何在UPDATEXML子句中声明名称空间。

当我尝试使用此代码更新

/ Workbook / a

中的值时,它可以正常工作:select UPDATEXML(xml_val, '/Workbook/a/text()',2020-01-08, 'xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"').getClobVal() as last from tt;
我尝试过但不起作用的不同名称空间组合:

-1

xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"

-2

xmlns="urn:schemas-microsoft-com:office:office" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"

-3

xmlns="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"

-4

xmlns="urn:schemas-microsoft-com:office:office"

注意:我无法在DocumentProperties标记中删除名称空间声明,因为此XML来自Excel-XML格式文件
xml oracle xml-namespaces updatexml
1个回答
0
投票
DocumentProperties元素及其子元素位于具有快捷方式urn:schemas-microsoft-com:office:office的名称空间o中;您需要在Xpath中为这些元素添加名称空间前缀:

SELECT UPDATEXML( xml_val, '/Workbook/o:DocumentProperties/o:Created/text()', '2020-01-08', 'xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"' ) AS updated_xml FROM tt;

| UPDATED_XML || :------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------ || XXXXXX Author> UCB用户 LastAuthor> 2020-01-08 Created> 14.00 Version> DocumentProperties> < a> 5 Workbook> |

db <>小提琴here

但是,UPDATEXML已过时,应使用XMLQUERY

SELECT XMLQuery( 'declare default element namespace "urn:schemas-microsoft-com:office:spreadsheet"; (: :) declare namespace o = "urn:schemas-microsoft-com:office:office"; (: :) copy $i := $x modify ( for $j in $i/Workbook/o:DocumentProperties/o:Created return replace value of node $j with $v ) return $i' PASSING xml_val AS "x", '2020-01-08' AS "v" RETURNING CONTENT ) AS updated_xml FROM tt

db <>小提琴here

© www.soinside.com 2019 - 2024. All rights reserved.