Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any() linq query on XmlNodeList

Tags:

c#

xml

linq

I am not able to use Any() on XmlNodeList. I have also used System.Linq and System.Xml.Linq namespaces as well. But still I'm not finding any such extension methods on XmlNodeList.

How I can use it??

like image 436
Amol Bavannavar Avatar asked Dec 08 '22 01:12

Amol Bavannavar


1 Answers

The problem is that XmlNodeList only implements IEnumerable, not IEnumerable<T>. The simplest way to use LINQ on it is to call Cast:

var query = nodeList.Cast<XmlNode>()
                    .Where(...)
                    ...;

Alternatively, ditch the old XML API and use LINQ to XML, which is a much nicer API in general and supports LINQ really nicely :)

like image 156
Jon Skeet Avatar answered Dec 11 '22 07:12

Jon Skeet