开发者

linq to xml - remove elements

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜