I need to get hold of all the elements in an XDocument, regardless of name, whose value matches some criterion.
The 'matching a criterion' part isn't the problem - the problem is how to get a collection of all the XElements in an XDocument, in other words to flatten it into a 'list' of XElements, without specifying the element names.
myXDocument.Descendants().Where(el => IsAMatch(el.Value))
only seems to return the first level, but the elements in question are nested a variety of levels deep and have a variety of names over which I have no control (and to be honest, no interest either. I just want to find them).
I could do it recursively, walking the tree and adding every matching element to a list, but it doesn't seem very elegant (and is probably quite slow).
How can do I do this more elegantly?
TIA