I am trying to get all descendant XElements including root element of an XElement according to presence of specific attribute. My not very nice attempt:
var myXElements = form.FormData.Descendants().Where(e => e.Attributes().Where(a => a.Name == myProperty).Count() > 0).ToList();
// Extra for root element
if (form.FormData.Attribute(myProperty) != null)
{
myXElements.Add(form.FormData);
}
where form.FormData is XElement type (I recive it from .dll) and myProperty is the specific property.
Is there more elegent way to achive this?