1

我有一个xml结构如下

<DifficultyRule xmlns="urn:gjensidige:processguide:201201">
 <Id>fc39f423-05c0-4de9-ae46-12fe3c0c279b</Id>
 <Code>5595e558-7d10-4767-86dc-5d16f24b8151_Code</Code>
 <Author />
 <Updated>9/5/2012</Updated>
 <Sequence>0</Sequence>
 <FromControls>
 <Control>
  <Code>oiuyui</Code>
  <Id>70579cbe-c0b5-4b49-a7b8-6201af388f59</Id>
  <FilterValues>
     <FilterValue xmlns:p5="urn:gjensidige:processguide:201201" p5:Id="b897f3ac-b40f-4b96-b438-eb156a26457e" p5:Code="e" p5:LookupId="3fa26ce7-4031-4e41-92cb-50d8ce56d262" />
   </FilterValues>
 </Control>
</FromControls>
<DifficultyCode>Red</DifficultyCode>
</DifficultyRule>

我正在尝试删除 xpath 中的 FilterValue 节点

/qn:DifficultyRule/qn:FromControls/qn:Control/qn:FilterValues/qn:FilterValue 

基于p5:Id属性的值,但我对为什么节点没有被删除感到困惑。

下面是我正在使用的脚本:

declare @lookupvalueId varchar(50)
declare @ruleId varchar(50)

set @lookupvalueId = 'b897f3ac-b40f-4b96-b438-eb156a26457e'
set @ruleId = 'fc39f423-05c0-4de9-ae46-12fe3c0c279b'

;WITH XMLNAMESPACES ('urn:gjensidige:processguide:201201' as qn)
update pdr_processdefinitionrule
set PDR_RuleXml.modify('delete (/qn:DifficultyRule/qn:FromControls/qn:Control/qn:FilterValues/qn:FilterValue[@Id=sql:variable("@lookupvalueId")])')
where pdr_guid = @ruleId

我错过了什么?任何指导将不胜感激

4

1 回答 1

0

好吧,由于您的 XML 属性id是带有前缀的 XML 命名空间,因此p5您还必须在代码中声明并使用第二个 XML 命名空间:

declare @lookupvalueId varchar(50)
declare @ruleId varchar(50)

set @lookupvalueId = 'b897f3ac-b40f-4b96-b438-eb156a26457e'
set @ruleId = 'fc39f423-05c0-4de9-ae46-12fe3c0c279b'

;WITH XMLNAMESPACES ('urn:gjensidige:processguide:201201' as qn,
                     'urn:gjensidige:processguide:201201' as p5)
update 
    pdr_processdefinitionrule
set 
    PDR_RuleXml.modify('delete (/qn:DifficultyRule/qn:FromControls/qn:Control/qn:FilterValues/qn:FilterValue[@p5:Id=sql:variable("@lookupvalueId")])')
where 
    pdr_guid = @ruleId

看到第二个 XML 命名空间定义了p5吗?qn:FilterValue[@p5:Id=sql:variable("@lookupvalueId")]看到表达式中那个 XML 命名空间的使用了吗?

于 2012-09-06T12:42:14.377 回答