linq to xml - 删除元素

发布于 2024-10-29 07:08:59 字数 150 浏览 3 评论 0原文

我想删除所有 Item 类型的元素,其属性 view 没有特定值。

所以如果值为XXX。选择属性视图值为 != XXX 的所有元素 Item。

某些 Item 元素没有 view 属性。不应选择此元素。

I'd like to remove all elements of type Item with an attribute view which has not a certain value.

So if the value is XXX. Select all elements Item which have an attribute view of value != XXX.

Some of the Item elements don't have a view attribute. This elements shouldn't be selected.

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

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

发布评论

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

评论(1

白云悠悠 2024-11-05 07:08:59
string selector = "XXX";

Elements.Where(x => x.Name == "Item"
                 && x.Attribute("view") != null
                 && x.Attribute("view").Value != selector).Remove();
string selector = "XXX";

Elements.Where(x => x.Name == "Item"
                 && x.Attribute("view") != null
                 && x.Attribute("view").Value != selector).Remove();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文