title: Using a filter list with linq to xml
body: <p>Is there a way to pass a list of strings to a linq to xml query or do I need to specify each filter separately? I want to count the number of elements that have the same name as the strings in a list.</p>
  
  <p>Here's code that obviously doesn't work but gives you an idea what I'm looking to do:</p>
  
  <pre><code>XDocument doc = XDocument.Load(pathToXmlFile);
  
  List&lt;string&gt; myList = new List&lt;string&gt; { "node1", "node2" };
  
  int count = doc.Descendants().Where(x =&gt; x.Element(myList)).Count();
  </code></pre>
  
  <p>Obviously, x.Element can't take a list of strings, but is there another way to do this other than typing out individual x.Element("node1"), x.Element("node2"), etc?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I wasn't able to get it working with implicit conversion to XName, so this is how I did it:</p>
  
  <pre><code>int count = doc.Descendants().Where(x =&gt; myList.Any(n =&gt; x.Name.ToString() == n)).Count();
  </code></pre>
  
  <p>The key to this was the Any method.</p>