Frage

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, distinguish 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?

War es hilfreich?

Lösung

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;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top