Could someone give me a code example of this that does work. I tried:
DECLARE @xml xml;
DECLARE @expression nvarchar(128);
SET @xml =
'<books>
<book price=''31'' name=''SQL Server Central'' Author=''Steve Jones''/>
</books>';
--SET @expression = '/books/book/@price[text()=31]';
IF @xml.exist('/books/book/@price[text()=31]') =1
SELECT
T.value('./@price[1]','int'),
T.value('./@name[1]','nvarchar(32)'),
T.value('./@Author[1]','nvarchar(32)')
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:
/books/book/@price=31
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.
P.S.
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?
P.P.S
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.