Reputation: 3281
I have the following example
DECLARE @MyXml XML
SET @MyXml = CONVERT(XML, '<?xml version="1.0" ?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<number xsi:nil="true" />
</root>')
SELECT @MyXml.value('(/root/number)[1]', 'INT') AS MyNumber
The above listing gives me a 0 instead of a NULL
that I would expect. I know I am using Schema Instance
, but shouldn't it be a widely accepted standard already?
Upvotes: 2
Views: 314
Reputation: 175934
You can use text()
:
DECLARE @MyXml XML
SET @MyXml = CONVERT(XML,
'<?xml version="1.0" ?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<number xsi:nil="true" />
</root>')
SELECT @MyXml.value('(/root/number/text())[1]', 'INT') AS MyNumber
Upvotes: 1