在 SQL 查询中检测 XML nil

发布于 2024-12-02 04:44:21 字数 416 浏览 7 评论 0原文

我正在使用 MS SQL Server 2008。我有一个 XML 类型的列,用于存储某些序列化的结果。当被序列化的对象的值为 nothing/null 时,此结果存储在数据库中,

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

我正在构建一个查询,需要确定数据是否在XML 列表示是否为空对象。所以换句话来说,区分列什么时候有上面的值,或者是序列化的对象。

SQL Server 2008 中是否有内置的 XML 功能可以做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2024-12-09 04:44:21

下面是从顶级项读取 xsi:nil 属性的示例:

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文