【发布时间】:2017-09-15 22:35:01
【问题描述】:
我在 Sql server 中定义了以下映射。
declare @map xml = '<Maps><Map From="1" To="2"/><Map From="3" To="4" /></Maps>';
我需要使用映射在(示例)xml 之后更改属性Id 的值。但是,根元素可以是任何东西,我想保留所有其他属性。
declare @x xml;
set @x = '<XX><Value Id="1" OtherAttrs="..." /><Value Id="3" /></XX>';
-- Expect <XX><Value Id="2" OtherAttrs="..." /><Value Id="4" /></XX>
set @x = '<YY><Value Id="3" /><Value Id="1" OtherAttrs="..." /></YY>';
-- Expect <YY><Value Id="4" /><Value Id="2" OtherAttrs="..." /></YY>
select @x.query('...') -- How to write the xquery?
如何编写 xquery 脚本?
如果我只有两种根元素<XX> 和<YY> 怎么办?
【问题讨论】:
-
这是一个错字,我修正了它。谢谢。
标签: sql-server xml xpath xquery