我的表中有一个名为“Content_Html”的 xml 列,其中的数据如下所示:
<root>
<Category>Cover Impression</Category>
<Title>Mystery of the Wolves</Title>
<Month>April</Month>
...
...
</root>
我正在尝试替换 <Category>
下的元素从 Cover Impression 到 Cover Impressions,在替换之后,我的这个类别的表格应该看起来像
<Category>Cover Impressions</Category>
我查看了这篇文章 (http://stackoverflow.com/questions/7316712/how-to-rename-xml-node-name-in-a-sql-server) 以了解我的问题,但不完全是我的问题寻找。
有人能给我指出正确的方向吗?
根据下面的建议我尝试了这个:
declare @newValue XML
select @newValue = 'Cover Impressions'
update dbo.content
set content_html.modify('replace value of (/root/Category/text())[1] with sql:variable("@newValue")')
但给我“无法在 ntext 上调用方法”错误 谢谢,
最佳答案
你可以这样试试..
对于这段代码..
<Sample>
<NodeOne>Value1</NodeOne>
<NodeTwo>Value2</NodeTwo>
<NodeThree>OldValue</NodeThree>
</Sample>
用“NewValue”替换 NodeThree 中的“OldValue”。
DECLARE @newValue varchar(50)
SELECT @newValue = 'NewValue'
UPDATE [Product]
SET ProductXml.modify('replace value of (/Sample/NodeThree/text())[1] with sql:variable("@newValue")')
请为 more information 完成此操作
关于c# - 如何修改sql server中的xml节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8174181/