开发者

Detecting XML nil in SQL Query

I'm using MS SQL Server 2008. I have a column of type XML that I am storing the result of some serialization. When the value of the object being serialized is nothing/null this result is stored in the database,

<StaticModifiedProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" />

I am building a query that needs to determine whether or not the data in the XML column represents a null object or not. So in other words, distingu开发者_如何转开发ish when the column has the above value, or a serialized object.

Is there any built in XML functionality in SQL Server 2008 that can do this?


Here's an example to read the xsi:nil attribute from the top-level item:

declare @t table(x xml);
insert @t values (N'<StaticModifiedProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-    instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" />')
select x.value('(StaticModifiedProduct/@xsi:nil)[1]', N'nvarchar(5)') from @t;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜