update tbl_xml set mov_vcds.modify('replace value of(/videos/video/title/text())[1] with "Anbu"')
without text() can we use this query..
update tbl_xml set mov_vcds.modify('replace value of(/videos/video/title/text())[1] with "Anbu"')
without text() can we use this query..
text()
specifies the content of the title
node. Without it you get
Msg 2356, Level 16, State 1, Line 9
XQuery [tbl_xml.mov_vcds.modify()]: The target of 'replace value of' must be a non-metadata attribute or an element with simple typed content, found 'element(title,xdt:untyped) ?'
So you need it.
It's unfortunately very common to see "text()" used in this way at the end of a path expression where it is unnecessary and occasionally harmful. Usually you can use the element node itself in contexts where you are referring to the content of the element. There are a few exceptions, for example in an element constructor
<title>{title}</title>
and
<title>{title/text()}</title>
do different things (the first gives you <title><title>original title</title></title>
). But in this case it's usually better to use title/string()
because that copes better with nested comments, mixed content, etc.