1

我有一个xml结构如下

<ControlVisibilityRule xmlns="urn:gjensidige:processguide:201201">
   <Id>e68c53a3-79ba-41e4-81cb-341050016783</Id>
   <Code>b53b687c-2617-4d02-8aa0-4d0d0898bd15_Code</Code>  
   <Author />  
   <Updated>9/5/2012</Updated>  
   <Sequence>0</Sequence>  
   <FromControls>    
       <Control>      
            <Code>ada</Code>      
            <Id>ba2abc55-3b25-4280-8bd0-a1d23a4575d0</Id>      
            <FilterValues>        
                <FilterValue xmlns:p5="urn:gjensidige:processguide:201201" p5:Id="e2b830f8-9a58-4edf-b56c-4c5a9580f362" p5:Code="1" p5:LookupId="ebb6066f-a976-4dcb-aabe-07c4f7d2686b" />
                <FilterValue xmlns:p5="urn:gjensidige:processguide:201201" p5:Id="44e268ef-2869-4df1-b61e-c59c2d3f1a5a" p5:Code="56" p5:LookupId="ebb6066f-a976-4dcb-aabe-07c4f7d2686b" />
            </FilterValues>    
       </Control>  
   </FromControls>  
   <ToControls>    
       <Control>      
           <Code>adeUnittest01</Code>      
           <Id>0a1cd240-20ee-4405-9613-d3006693c390</Id>    
       </Control>  
   </ToControls>  
   <IsVisible>True</IsVisible>
</ControlVisibilityRule>

我想删除 xpath 中的元素 ID

/qn:ControlVisibilityRule/qn:ToControls/qn:Control/qn:Id  

其值为0a1cd240-20ee-4405-9613-d3006693c390。我已经完成了下面的工作,但我确定我缺少元素值与变量的比较。

 declare @Id nvarchar(50)
 declare @ruleId nvarchar(50) 

 ;WITH XMLNAMESPACES ('urn:gjensidige:processguide:201201' as qn)
 update 
     pdr_processdefinitionrule
 set 
     PDR_RuleXml.modify('delete (/qn:ControlVisibilityRule/qn:ToControls/qn:Control/qn:Id=sql:variable("@Id"))')
 where pdr_guid = @ruleId   

任何指导将不胜感激

4

1 回答 1

0

你需要这样做:

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

基本上,您想删除与您的变量(XMLqn:Id元素text()包含的文本)匹配的元素@Id

于 2012-09-06T11:40:00.797 回答