Hi, how to get a collection of all the leaves of a XElement tree regardless the hierarchy? Thanks
+4
A:
Is the Descendants()
method what you're after?
That will get all descendants - to get only the leaves, you could use LINQ to Objects with a Where
clause:
element.Descendants()
.Where(desc => !desc.Elements().Any());
(Note this is still only elements, not other nodes like text nodes. Hope that's okay.)
Jon Skeet
2009-06-24 15:36:37