简体   繁体   English

XQuery [modify()]: 命名空间前缀 'dt' 尚未定义

[英]XQuery [modify()]: The namespace prefix 'dt' has not been defined

I am trying to update an existing XML column value in SQL Server.我正在尝试更新 SQL Server 中现有的 XML 列值。

declare @xml xml;
select @xml = 
'<items xmlns:dt="urn:schemas-microsoft-com:datatypes">
<item dt:dt="string">Item1<item>
</items>';
set @xml.modify('insert <item dt:dt="string">Item2</item> into (/items)[1]');

This throws the error: XQuery [modify()]: The namespace prefix 'dt' has not been defined这会引发错误:XQuery [modify()]: The namespace prefix 'dt' has not been defined

How can I get the namespace in to the modify?如何将命名空间放入修改中?

declare @xml xml;
select @xml = 
'<items xmlns:dt="urn:schemas-microsoft-com:datatypes">
<item dt:dt="string">Item1</item>
</items>';
select @xml;

set @xml.modify('declare namespace dt="urn:schemas-microsoft-com:datatypes"; insert <item dt:dt="string">Item2</item> into (/items)[1]');

select @xml;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM