开发者

linq to xml - remove elements

开发者 https://www.devze.com 2023-02-22 04:04 出处:网络
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.

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 vie开发者_开发百科w attribute. This elements shouldn't be selected.


string selector = "XXX";

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

精彩评论

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