O.O
O.O

Reputation: 11317

Check if xml values are contained within a list

I have:

var results = response.Xml.Descendants("M").Where(foo => foo.Value.Contains("john"));

How do I change this to be:

List<string> ValidUsers = new List<string>();
ValidUsers.Add("John");
ValidUsers.Add("Smurf");
var results = response.Xml.Descendants("M")
    .Where(foo => foo.Value.Contains(ValidUsers));

Upvotes: 0

Views: 55

Answers (2)

O.O
O.O

Reputation: 11317

Figured it out:

var results = doc.Descendants("M")
    .Where(foo => ValidUsers.Any(s => foo.Value.Contains(s)));

Upvotes: 0

Marc
Marc

Reputation: 6771

Switch it (just a guess, not testet).

Not foo.Value.Contains(ValidUsers) but ValidUsers.Contains(foo.Value).

Upvotes: 1

Related Questions