1
update tbl_xml set mov_vcds.modify('replace value of(/videos/video/title/text())[1] with "Anbu"') 

without text() can we use this query..

Anboo
  • 103
  • 2
  • 17

2 Answers2

4

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.

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
  • 1
    That error message bears no relationship to anything in the W3C spec. It seems to be a product-specific restriction. Unfortunately there are lots of "approximate" implementations of XQuery Update out there. The reference to the "xdt" prefix suggests this product isn't up-to-date with the specifications, since that prefix disappeared from the specs around 2005. – Michael Kay Mar 02 '12 at 11:40
2

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164