i need remove xml element has attribute of a
value of xxxx
xml values in column.
method 1:
update t set x = x.query('//e[@a != "xxxx"]')
method 2:
update t set x.modify('delete /e[@a = "xxxx"]')
which 1 better?
both calls not same:
declare @xml xml= n'<root> <test pos="1" a="xxx">test 1</test> <test pos="2" a="someother">test 2</test> <test pos="3" a="xxx">test 3</test> <otherelement>this element</otherelement> </root>';
--try either approach
set @xml=@xml.query(n'//test[@a!="xxx"]')
--or try this
set @xml.modify(n'delete //test[@a="xxx"]') select @xml;
the result of first is
<test pos="2" a="someother">test 2</test>
while second returns
<root> <test pos="2" a="someother">test 2</test> <otherelement>this element</otherelement> </root>
xml not stored text see. stored tree structure representing complex document. modify easy, kick out elements. query()
approach has rebuild xml , replace first new one. clear advise is: use modify()
approach! if xquery
, flwor
query()
approach mightier, story...
Comments
Post a Comment