English 中文(简体)
• 如何改变与锡克文对应的内容案文?
原标题:How to change matched element text with XQuery?
  • 时间:2009-10-14 17:46:46
  •  标签:

我试图把我所看到的找到要素和修改这些要素的所有例子混在一起,但我没有看到一些行之有效的做法。 我举了一个例子,说明我迄今为止在2005年服务器上运行的情况。 I m 试图将项目4改为999:

DECLARE @x XML
SELECT @x =  
<ValueCollection>
  <ItemGroup Name="Group A">
    <ItemID>1</ItemID>
    <ItemID>2</ItemID>
  </ItemGroup>
  <ItemGroup Name="Group B">
    <ItemID>3</ItemID>
    <ItemID>4</ItemID>
  </ItemGroup>
</ValueCollection>
 ;

SET @x.modify ( 
replace value of
    (/ValueCollection/ItemGroup[ItemID="4"]/ItemID/text())[1]
with "999"
 )

SELECT @x;

但是,正如以下成果所示,项目3正改为999,而不是4。 我认为,正在发生的是,“项目组”4 正在定位正确与设计;项目组和“项目组”;然后,职位过滤器...... *** 投放了第1版;项目设计与设计;项目组和项目;(即ID 3)—— 我只字不提如何将职位过滤改为变量。

<ValueCollection>
  <ItemGroup Name="Group A">
    <ItemID>1</ItemID>
    <ItemID>2</ItemID>
  </ItemGroup>
  <ItemGroup Name="Group B">
    <ItemID>999</ItemID>
    <ItemID>4</ItemID>
  </ItemGroup>
</ValueCollection>

I have a feeling it is something simple that my googling and stackoverflowing hasn t turned up yet. I appreciate your help!
Kevin

最佳回答
SET @x.modify ( replace value of
    (/ValueCollection/ItemGroup/ItemID[text()=4]/text())[1]
    with "999"
     )

或如果你想要更确切:

SET @x.modify ( replace value of
    (/ValueCollection/ItemGroup[@Name="Group B"]/ItemID[text()=4]/text())[1]
     with "999"
     )
问题回答

暂无回答




相关问题
热门标签