Could someone give me a code example of this that does work. I tried:
DECLARE @xml xml;
DECLARE @expression nvarchar(128);
SET @xml =
<book price=''31'' name=''SQL Server Central'' Author=''Steve Jones''/>
--SET @expression = '/books/book/@price[text()=31]';
IF @xml.exist('/books/book/@price[text()=31]') =1
FROM @xml.nodes('/books/book') AS T(T);
and I get the error:
XQuery [exist()]: Result of 'text()' expression is statically 'empty'
So I replace the XPath expression with:
and it works.
I don't use Xml and XPath every day, but I understand most of the basic concepts. What should the Xml look like in order to use the original XPath expression? The '@price' means an attribute and 'text()' all the text within a node. To me, the XPath expression is invalid or just doesn't make sense.
Did the author just do the same thing I did and forget to escape out the '<' with '& lt;' in the Xml string when writing and posting the question?
I can't get an escaped ampersand followed by 'lt;', as in above to show up in these forums without manually putting that space between them.