I am learning LINQ for XML and must find the existence of an element with a specific attribute. At the moment I am using:
XElement groupCollectionXml = XElement.Parse(groupCollection.Xml);
IEnumerable<XElement> groupFind =
from vw in groupCollectionXml.Elements("Group")
where (string) vw.Attribute("Name") == groupName
select vw;
if (groupFind.Count() == 0)
return false;
else
return true;
I know there is a more concise way to do this, possibly using Any (), but I'm not sure how to rewrite the request to use it. Anyone have any good advice? Thanks.
source
share