简体   繁体   English

sql + xquery删除多个父节点

[英]sql + xquery to delete multiple parent nodes

In the below xml i have three 5 /Item elements, 4 of which have a Blob child element. 在下面的xml中,我有三个5 / Item元素,其中4个具有Blob子元素。 I want to delete the elements that have a child Blob element but only where Item/@Name has the text "Blob" in it. 我要删除具有子Blob元素但仅在Item / @ Name中包含文本“ Blob”的元素。

<Items>
    <Item Name="Blob123">
        <Blob/>
    </Item>
    <Item Name="Blob124">
        <Blob/>
    </Item>
    <Item Name="Blob125">
        <Blob/>
    </Item>
    <Item Name="Blob126">
    </Item>
    <Item Name="Xyz126">
        <Blob/>
    </Item>
</Items>

This query returns the 3 /Item elements named 'Blob%' and with a child /Blob element just fine. 该查询返回名为'Blob%'的3个/ Item元素,并带有一个子/ Blob元素就好了。

  select xmlVal.query('(/Items/Item[contains(@Name, "Blob")]/Blob/..)')

However when i attempt to delete those element using this xquery: 但是,当我尝试使用此xquery删除那些元素时:

  select xmlVal.modify('delete (/Items/Item[contains(@Name, "Blob")]/Blob/..)')

I get: Incorrect use of the XML data type method 'modify'. 我得到:XML数据类型方法'modify'的错误使用。 A non-mutator method is expected in this context. 在这种情况下,期望使用非突变方法。

What am i doing wrong. 我究竟做错了什么。

In case it helps others, to fix this i need to use update/set and also needed to change the xpath slightly 如果它可以帮助其他人,要解决此问题,我需要使用更新/设置,还需要稍微更改xpath

update table1 set xmlVal.modify('delete (/Items/Item[contains(@Name, "Blob")][Blob])') 更新table1 set xmlVal.modify('删除(/ Items / Item [包含(@Name,“ Blob”)] [Blob])')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM